guix-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

branch master updated: guix-install.sh: Restore compatibility with "yes"


From: guix-commits
Subject: branch master updated: guix-install.sh: Restore compatibility with "yes" invocation.
Date: Tue, 11 Oct 2022 12:03:00 -0400

This is an automated email from the git hooks/post-receive script.

apteryx pushed a commit to branch master
in repository guix.

The following commit(s) were added to refs/heads/master by this push:
     new e46bb5fd5a guix-install.sh: Restore compatibility with "yes" 
invocation.
e46bb5fd5a is described below

commit e46bb5fd5af3adb931e0930326c60a7c2e4cbe4e
Author: Maxim Cournoyer <maxim.cournoyer@gmail.com>
AuthorDate: Tue Oct 11 11:49:37 2022 -0400

    guix-install.sh: Restore compatibility with "yes" invocation.
    
    Commit 6a2e303d3a had modified prompt_yes_no to only read a single 
character,
    aiming to ease the user experience.  This was, in retrospect, a bad idea, as
    it makes user input error more likely and introduces complexity.
    
    This commit reverts to line-oriented input, while preserving the default yes
    value so that a user can simply hit 'Enter' at the prompt in place of typing
    "yes".
    
    * etc/guix-install.sh (_flush): Delete function.
    (prompt_yes_no): Restore line-oriented read.  Remove loop.  Make anything 
else
    than yes means no.  Use Bash features to streamline definition.
    
    Reported-by: Lars-Dominik Braun <lars@6xq.net> and others.
---
 etc/guix-install.sh | 25 ++++++-------------------
 1 file changed, 6 insertions(+), 19 deletions(-)

diff --git a/etc/guix-install.sh b/etc/guix-install.sh
index f71d6f0de7..3604c71ed6 100755
--- a/etc/guix-install.sh
+++ b/etc/guix-install.sh
@@ -92,33 +92,20 @@ _debug()
     fi
 }
 
-_flush()
-{
-    while read -t0; do
-        read -N1
-    done
-}
-
 die()
 {
     _err "${ERR}$*"
     exit 1
 }
 
-# Return true if user answered yes, false otherwise.  It defaults to "yes"
-# when a single newline character is input.
+# Return true if user answered yes, false otherwise.  The prompt is
+# yes-biased, that is, when the user simply enter newline, it is equivalent to
+# answering "yes".
 # $1: The prompt question.
 prompt_yes_no() {
-    while true; do
-        _flush
-        read -N1 -rsp "$1 [Y/n]" yn
-        case $yn in
-            $'\n') echo && return 0;;
-            [Yy]*) echo && return 0;;
-            [Nn]*) echo && return 1;;
-            *) echo && _msg "Please answer yes or no."
-        esac
-    done
+    local -l yn
+    read -rp "$1 [Y/n]" yn
+    [[ ! $yn || $yn = y || $yn = yes ]] || return 1
 }
 
 chk_require()



reply via email to

[Prev in Thread] Current Thread [Next in Thread]