1
0
mirror of https://github.com/ohmyzsh/ohmyzsh.git synced 2024-11-22 06:50:49 +08:00

feat(updater): do not update when user already typed some characters (#9699)

Fixes #9699
This commit is contained in:
Marc Cornellà 2022-02-07 18:58:47 +01:00
parent 1e26ad1187
commit f0f42828fa
No known key found for this signature in database
GPG Key ID: 0314585E776A9C1B

View File

@ -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
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 $?
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\`"
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