summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorMarc Cornellà <hello@mcornella.com>2022-02-07 18:58:47 +0100
committerMarc Cornellà <hello@mcornella.com>2022-02-07 18:58:47 +0100
commitf0f42828fa6842af631cc3dbf45f5454ea88fa3c (patch)
treef4dbfd28759b046738ce44d177f943afc0a15b08 /tools
parent1e26ad1187cdee286d0332dbdffb6828a71140c2 (diff)
downloadzsh-f0f42828fa6842af631cc3dbf45f5454ea88fa3c.tar.gz
zsh-f0f42828fa6842af631cc3dbf45f5454ea88fa3c.tar.bz2
zsh-f0f42828fa6842af631cc3dbf45f5454ea88fa3c.zip
feat(updater): do not update when user already typed some characters (#9699)
Fixes #9699
Diffstat (limited to 'tools')
-rw-r--r--tools/check_for_upgrade.sh41
1 files changed, 25 insertions, 16 deletions
diff --git a/tools/check_for_upgrade.sh b/tools/check_for_upgrade.sh
index 3f6d35c3e..4484df4fe 100644
--- a/tools/check_for_upgrade.sh
+++ b/tools/check_for_upgrade.sh
@@ -146,26 +146,35 @@ function update_ohmyzsh() {
return
fi
- # Ask for confirmation before updating unless in auto mode
+ # Don't ask for confirmation before updating if in auto mode
if [[ "$update_mode" = auto ]]; then
update_ohmyzsh
- elif [[ "$update_mode" = reminder ]]; then
+ return $?
+ fi
+
+ # If in reminder mode show reminder and exit
+ if [[ "$update_mode" = reminder ]]; then
echo "[oh-my-zsh] It's time to update! You can do that by running \`omz update\`"
- else
- # input sink to swallow all characters typed before the prompt
- # and add a newline if there wasn't one after characters typed
- while read -t -k 1 option; do true; done
- [[ "$option" != ($'\n'|"") ]] && echo
-
- echo -n "[oh-my-zsh] Would you like to update? [Y/n] "
- read -r -k 1 option
- [[ "$option" != $'\n' ]] && echo
- case "$option" in
- [yY$'\n']) update_ohmyzsh ;;
- [nN]) update_last_updated_file ;&
- *) echo "[oh-my-zsh] You can update manually by running \`omz update\`" ;;
- esac
+ return 0
fi
+
+ # If user has typed input, show reminder and exit
+ if read -t -k 1; then
+ echo
+ echo "[oh-my-zsh] It's time to update! You can do that by running \`omz update\`"
+ return 0
+ fi
+
+ # Ask for confirmation and only update on 'y', 'Y' or Enter
+ # Otherwise just show a reminder for how to update
+ echo -n "[oh-my-zsh] Would you like to update? [Y/n] "
+ read -r -k 1 option
+ [[ "$option" = $'\n' ]] || echo
+ case "$option" in
+ [yY$'\n']) update_ohmyzsh ;;
+ [nN]) update_last_updated_file ;&
+ *) echo "[oh-my-zsh] You can update manually by running \`omz update\`" ;;
+ esac
}
unset update_mode