From a0fdbe014937adce0dad19b99a278723afe6455c Mon Sep 17 00:00:00 2001 From: jutty Date: Sat, 31 Aug 2024 07:56:41 -0300 Subject: [PATCH] Add an exit option to ask dialog --- src/utility.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/utility.sh b/src/utility.sh index f713db0..79afd4d 100644 --- a/src/utility.sh +++ b/src/utility.sh @@ -68,14 +68,15 @@ ask() { dialog_options="$dialog_options\n [$options_count] $option" done; IFS= + dialog_options="$dialog_options\n [0] Exit" printf "%s" "$question" >&2 printf "%b" "$dialog_options" >&2 - printf "\n%s" "Choose an option [1-$options_count] " >&2 + printf "\n%s" "Choose an option number: " >&2 read -r read_answer answer="$(echo "$read_answer" | xargs)" - if [ "$answer" -gt 0 ] 2> /dev/null && [ "$answer" -le $options_count ]; then + if [ "$answer" -ge 0 ] 2> /dev/null && [ "$answer" -le $options_count ]; then echo "$answer" else log debug "[ask] Invalid choice"