feat(updater): do not update when user already typed some characters (#9699)
Fixes #9699
Diff
1diff --git a/tools/check_for_upgrade.sh b/tools/check_for_upgrade.sh
2index 3f6d35c3eed596e6a378e56c7e6c71ee559e66b5..4484df4fe5f509a053a9147a6cade7e927f01208 100644
3--- a/tools/check_for_upgrade.sh
4+++ b/tools/check_for_upgrade.sh
5@@ -146,26 +146,35 @@ function update_ohmyzsh() {
6 return
7 fi
8 9- # Ask for confirmation before updating unless in auto mode
10+ # Don't ask for confirmation before updating if in auto mode
11 if [[ "$update_mode" = auto ]]; then
12 update_ohmyzsh
13- elif [[ "$update_mode" = reminder ]]; then
14+ return $?
15+ fi
16+
17+ # If in reminder mode show reminder and exit
18+ if [[ "$update_mode" = reminder ]]; then
19 echo "[oh-my-zsh] It's time to update! You can do that by running \`omz update\`"
20- else
21- # input sink to swallow all characters typed before the prompt
22- # and add a newline if there wasn't one after characters typed
23- while read -t -k 1 option; do true; done
24- [[ "$option" != ($'\n'|"") ]] && echo
25-
26- echo -n "[oh-my-zsh] Would you like to update? [Y/n] "
27- read -r -k 1 option
28- [[ "$option" != $'\n' ]] && echo
29- case "$option" in
30- [yY$'\n']) update_ohmyzsh ;;
31- [nN]) update_last_updated_file ;&
32- *) echo "[oh-my-zsh] You can update manually by running \`omz update\`" ;;
33- esac
34+ return 0
35 fi
36+
37+ # If user has typed input, show reminder and exit
38+ if read -t -k 1; then
39+ echo
40+ echo "[oh-my-zsh] It's time to update! You can do that by running \`omz update\`"
41+ return 0
42+ fi
43+
44+ # Ask for confirmation and only update on 'y', 'Y' or Enter
45+ # Otherwise just show a reminder for how to update
46+ echo -n "[oh-my-zsh] Would you like to update? [Y/n] "
47+ read -r -k 1 option
48+ [[ "$option" = $'\n' ]] || echo
49+ case "$option" in
50+ [yY$'\n']) update_ohmyzsh ;;
51+ [nN]) update_last_updated_file ;&
52+ *) echo "[oh-my-zsh] You can update manually by running \`omz update\`" ;;
53+ esac
54 }
5556 unset update_mode