all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Maxim Cournoyer <maxim.cournoyer@gmail.com>
To: 58345@debbugs.gnu.org
Cc: Maxim Cournoyer <maxim.cournoyer@gmail.com>
Subject: [bug#58345] [PATCH 1/3] guix-install.sh: Improve prompt_yes_no procedure.
Date: Fri,  7 Oct 2022 01:31:58 -0400	[thread overview]
Message-ID: <20221007053200.21177-1-maxim.cournoyer@gmail.com> (raw)
In-Reply-To: <20221007052738.20637-1-maxim.cournoyer@gmail.com>

* etc/guix-install.sh (_flush): New function.
(prompt_yes_no): Clear input, then only read the first character, silently.
Add the [Yes/no] string to the message.  When a newline is entered by the
user, treat it as the default value, which is "yes".
(chk_gpg_keyring): Remove "(yes/no)" from the prompt message.
(configure_substitute_discovery): Likewise.
(sys_authorize_build_farms): Likewise.
---
 etc/guix-install.sh | 28 +++++++++++++++++++---------
 1 file changed, 19 insertions(+), 9 deletions(-)

diff --git a/etc/guix-install.sh b/etc/guix-install.sh
index 300681e111..8c05d19657 100755
--- a/etc/guix-install.sh
+++ b/etc/guix-install.sh
@@ -9,7 +9,7 @@
 # Copyright © 2020 Daniel Brooks <db48x@db48x.net>
 # Copyright © 2021 Jakub Kądziołka <kuba@kadziolka.net>
 # Copyright © 2021 Chris Marusich <cmmarusich@gmail.com>
-# Copyright © 2021 Maxim Cournoyer <maxim.cournoyer@gmail.com>
+# Copyright © 2021, 2022 Maxim Cournoyer <maxim.cournoyer@gmail.com>
 #
 # This file is part of GNU Guix.
 #
@@ -92,15 +92,25 @@ _debug()
     fi
 }
 
-# Return true if user answered yes, false otherwise.
+_flush()
+{
+    while read -t0; do
+        read -N1
+    done
+}
+
+# Return true if user answered yes, false otherwise.  It defaults to "yes"
+# when a single newline character is input.
 # $1: The prompt question.
 prompt_yes_no() {
     while true; do
-        read -rp "$1 " yn
+        _flush
+        read -N1 -rsp "$1 [Y/n]" yn
         case $yn in
-            [Yy]*) return 0;;
-            [Nn]*) return 1;;
-            *) _msg "Please answer yes or no."
+            $'\n') echo && return 0;;
+            [Yy]*) echo && return 0;;
+            [Nn]*) echo && return 1;;
+            *) echo && _msg "Please answer yes or no."
         esac
     done
 }
@@ -137,7 +147,7 @@ chk_gpg_keyring()
         if ! gpg --dry-run --list-keys "$gpg_key_id" >/dev/null 2>&1; then
             if prompt_yes_no "${INF}The following OpenPGP public key is \
 required to verify the Guix binary signature: $gpg_key_id.
-Would you like me to fetch it for you? (yes/no)"; then
+Would you like me to fetch it for you?"; then
                 wget "https://sv.gnu.org/people/viewgpg.php?user_id=$user_id" \
                      --no-verbose -O- | gpg --import -
             else
@@ -254,7 +264,7 @@ chk_sys_nscd()
 configure_substitute_discovery() {
     if grep -q -- '--discover=no' "$1" && \
             prompt_yes_no "Would you like the Guix daemon to automatically \
-discover substitute servers on the local network? (yes/no)"; then
+discover substitute servers on the local network?"; then
         sed -i 's/--discover=no/--discover=yes/' "$1"
     fi
 }
@@ -490,7 +500,7 @@ sys_enable_guix_daemon()
 sys_authorize_build_farms()
 { # authorize the public key of the build farm
     if prompt_yes_no "Permit downloading pre-built package binaries from the \
-project's build farm? (yes/no)"; then
+project's build farm?"; then
         guix archive --authorize \
              < ~root/.config/guix/current/share/guix/ci.guix.gnu.org.pub \
             && _msg "${PAS}Authorized public key for ci.guix.gnu.org"
-- 
2.37.3





  reply	other threads:[~2022-10-07  5:33 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-07  5:27 [bug#58345] [PATCH 0/3] Customize PS1 on foreign distributions Maxim Cournoyer
2022-10-07  5:31 ` Maxim Cournoyer [this message]
2022-10-07  5:31   ` [bug#58345] [PATCH 2/3] guix-install.sh: Introduce 'die' utility function Maxim Cournoyer
2022-10-07  8:30     ` zimoun
2022-10-07 12:23       ` Maxim Cournoyer
2022-10-07  5:32   ` [bug#58345] [PATCH 3/3] guix-install.sh: Add Bash prompt customization option Maxim Cournoyer
2022-10-07  8:34     ` zimoun
2022-10-07 12:28       ` bug#58345: " Maxim Cournoyer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221007053200.21177-1-maxim.cournoyer@gmail.com \
    --to=maxim.cournoyer@gmail.com \
    --cc=58345@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/guix.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.