From 2a4f5d419c62a5dc7e919cb6b577b9be9bde56ec Mon Sep 17 00:00:00 2001 From: deicidus Date: Fri, 26 May 2023 02:20:52 -0700 Subject: [PATCH] trying another way --- spells/cantrips/ask_yn | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/spells/cantrips/ask_yn b/spells/cantrips/ask_yn index 1df4d0b..3ebc29b 100755 --- a/spells/cantrips/ask_yn +++ b/spells/cantrips/ask_yn @@ -1,8 +1,5 @@ #!/bin/sh -# Define ask_yn, which asks a yes or no question and defaults to the specified choice. -# Outputs 1 for yes and 0 for no - ask_yn() { default=${2:-"y"} default=$(printf "%s" "$default" | tr '[:upper:]' '[:lower:]') @@ -15,14 +12,14 @@ ask_yn() { esac while true; do - trap 'stty sane; exit' INT + trap 'exit' INT printf "%s (%s): " "$1" "$prompt" - stty raw -echo - answer=$(head -c 1) || exit - stty -echo - printf "\n" + read -r answer || exit + if [ -z "$answer" ]; then + answer="$default" + break + fi case "$answer" in - "" ) answer="$default"; break;; y|Y) answer="y"; break;; n|N) answer="n"; break;; esac