69e29378915d53655d8fa8dc181b6cf526754569

Author
Marc Cornellà <hello@mcornella.com>
Committer
Marc Cornellà <hello@mcornella.com>
Date

Message

fix(updater): fix input check on non-interactive runs

Reference: https://www.zsh.org/mla/users/2022/msg00067.html

Diff

 1diff --git a/tools/check_for_upgrade.sh b/tools/check_for_upgrade.sh
 2index 33f30c85a7965c1fcf043a335c303c15980d67e4..a36aecb841a4ed8de2e9a71aaee78409690d38dc 100644
 3--- a/tools/check_for_upgrade.sh
 4+++ b/tools/check_for_upgrade.sh
 5@@ -95,13 +95,21 @@ function has_typed_input() {
 6   emulate -L zsh
 7   zmodload zsh/zselect
 8 
 9+  # Back up stty settings prior to disabling canonical mode
10+  # Consider that no input can be typed if stty fails
11+  # (this might happen if stdin is not a terminal)
12+  local termios
13+  termios=$(stty --save 2>/dev/null) || return 1
14   {
15-    local termios=$(stty --save)
16+    # Disable canonical mode so that typed input counts
17+    # regardless of whether Enter was pressed
18     stty -icanon
19 
20+    # Poll stdin (fd 0) for data ready to be read
21     zselect -t 0 -r 0
22     return $?
23   } always {
24+    # Restore stty settings
25     stty $termios
26   }
27 }