Skip to content

Commit 7fe72ef

Browse files
committed
fix buggy y/n prompt
1 parent 34397ac commit 7fe72ef

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

setup.sh

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,18 @@ execute_command() {
1414

1515
prompt_yes_no() {
1616
echo -e "\n\033[1;34m? $1\033[0m"
17-
read -p " $2 [Y/n]: " $3
18-
eval "$3=\${$3:-y}" # Set default to 'y' if input is empty
19-
}
20-
21-
prompt_input() {
22-
echo -e "\n\033[1;34m? $1\033[0m"
23-
read -p " $2: " $3
17+
while true; do
18+
if ! read -r -p " $2 [Y/n]: " response; then
19+
# Handle EOF (Ctrl+D)
20+
echo # Print a newline for better formatting
21+
exit 1 # Return with a non-zero status to indicate cancellation
22+
fi
23+
case $response in
24+
[Yy]* | '') eval "$3='y'"; return 0 ;;
25+
[Nn]*) eval "$3='n'"; return 0 ;;
26+
*) echo " Please answer yes (y) or no (n)." ;;
27+
esac
28+
done
2429
}
2530

2631
exit_gracefully() {

0 commit comments

Comments
 (0)