mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2024-12-26 16:28:58 +01:00
feat(updater): do not update when user already typed some characters (#9699)
Fixes #9699
This commit is contained in:
parent
1e26ad1187
commit
f0f42828fa
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user