diff options
| author | Maxim Cournoyer <maxim.cournoyer@gmail.com> | 2022-10-11 11:49:37 -0400 |
|---|---|---|
| committer | Maxim Cournoyer <maxim.cournoyer@gmail.com> | 2022-10-11 12:00:44 -0400 |
| commit | e46bb5fd5af3adb931e0930326c60a7c2e4cbe4e (patch) | |
| tree | d5785e3dcf7ed1f5ed15726cd2c5ec5c59ee7671 /etc | |
| parent | 68d79a8b60a1a564a8425de8220fb65dc79ba9ee (diff) | |
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.
Diffstat (limited to 'etc')
| -rwxr-xr-x | etc/guix-install.sh | 25 |
1 files changed, 6 insertions, 19 deletions
diff --git a/etc/guix-install.sh b/etc/guix-install.sh index f71d6f0de71..3604c71ed6b 100755 --- a/etc/guix-install.sh +++ b/etc/guix-install.sh | |||
| @@ -92,33 +92,20 @@ _debug() | |||
| 92 | fi | 92 | fi |
| 93 | } | 93 | } |
| 94 | 94 | ||
| 95 | _flush() | ||
| 96 | { | ||
| 97 | while read -t0; do | ||
| 98 | read -N1 | ||
| 99 | done | ||
| 100 | } | ||
| 101 | |||
| 102 | die() | 95 | die() |
| 103 | { | 96 | { |
| 104 | _err "${ERR}$*" | 97 | _err "${ERR}$*" |
| 105 | exit 1 | 98 | exit 1 |
| 106 | } | 99 | } |
| 107 | 100 | ||
| 108 | # Return true if user answered yes, false otherwise. It defaults to "yes" | 101 | # Return true if user answered yes, false otherwise. The prompt is |
| 109 | # when a single newline character is input. | 102 | # yes-biased, that is, when the user simply enter newline, it is equivalent to |
| 103 | # answering "yes". | ||
| 110 | # $1: The prompt question. | 104 | # $1: The prompt question. |
| 111 | prompt_yes_no() { | 105 | prompt_yes_no() { |
| 112 | while true; do | 106 | local -l yn |
| 113 | _flush | 107 | read -rp "$1 [Y/n]" yn |
| 114 | read -N1 -rsp "$1 [Y/n]" yn | 108 | [[ ! $yn || $yn = y || $yn = yes ]] || return 1 |
| 115 | case $yn in | ||
| 116 | $'\n') echo && return 0;; | ||
| 117 | [Yy]*) echo && return 0;; | ||
| 118 | [Nn]*) echo && return 1;; | ||
| 119 | *) echo && _msg "Please answer yes or no." | ||
| 120 | esac | ||
| 121 | done | ||
| 122 | } | 109 | } |
| 123 | 110 | ||
| 124 | chk_require() | 111 | chk_require() |
