From 805427e06bc0549c7b9a4f50d3e39bbf68043f16 Mon Sep 17 00:00:00 2001 From: Marc Cornellà Date: Thu, 13 Jan 2022 17:28:15 +0100 Subject: fix(updater): give priority to `zstyle` settings if set (#10587) Fixes #10587 --- tools/check_for_upgrade.sh | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'tools/check_for_upgrade.sh') diff --git a/tools/check_for_upgrade.sh b/tools/check_for_upgrade.sh index 293f48edf..729d8ecb5 100644 --- a/tools/check_for_upgrade.sh +++ b/tools/check_for_upgrade.sh @@ -10,11 +10,13 @@ fi # - auto: the update is performed automatically when it's time # - reminder: a reminder is shown to the user when it's time to update # - disabled: automatic update is turned off -zstyle -s ':omz:update' mode update_mode || update_mode=prompt +zstyle -s ':omz:update' mode update_mode || { + update_mode=prompt -# Support old-style settings -[[ "$DISABLE_UPDATE_PROMPT" != true ]] || update_mode=auto -[[ "$DISABLE_AUTO_UPDATE" != true ]] || update_mode=disabled + # If the mode zstyle setting is not set, support old-style settings + [[ "$DISABLE_UPDATE_PROMPT" != true ]] || update_mode=auto + [[ "$DISABLE_AUTO_UPDATE" != true ]] || update_mode=disabled +} # Cancel update if: # - the automatic update is disabled. -- cgit v1.2.3-70-g09d2 From 84931adcd465e9a3b5e38f3b416a1df2acc33801 Mon Sep 17 00:00:00 2001 From: Marc Cornellà Date: Fri, 21 Jan 2022 19:03:35 +0100 Subject: fix: do not call chpwd hooks in subshells --- lib/cli.zsh | 10 +++++----- tools/check_for_upgrade.sh | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) (limited to 'tools/check_for_upgrade.sh') diff --git a/lib/cli.zsh b/lib/cli.zsh index 70076bcfb..2f3f293da 100644 --- a/lib/cli.zsh +++ b/lib/cli.zsh @@ -37,7 +37,7 @@ function _omz { elif (( CURRENT == 3 )); then case "$words[2]" in changelog) local -a refs - refs=("${(@f)$(cd "$ZSH"; command git for-each-ref --format="%(refname:short):%(subject)" refs/heads refs/tags)}") + refs=("${(@f)$(builtin cd -q "$ZSH"; command git for-each-ref --format="%(refname:short):%(subject)" refs/heads refs/tags)}") _describe 'command' refs ;; plugin) subcmds=( 'disable:Disable plugin(s)' @@ -176,7 +176,7 @@ function _omz::changelog { local version=${1:-HEAD} format=${3:-"--text"} if ( - cd "$ZSH" + builtin cd -q "$ZSH" ! command git show-ref --verify refs/heads/$version && \ ! command git show-ref --verify refs/tags/$version && \ ! command git rev-parse --verify "${version}^{commit}" @@ -761,7 +761,7 @@ function _omz::theme::use { } function _omz::update { - local last_commit=$(cd "$ZSH"; git rev-parse HEAD) + local last_commit=$(builtin cd -q "$ZSH"; git rev-parse HEAD) # Run update script if [[ "$1" != --unattended ]]; then @@ -777,7 +777,7 @@ function _omz::update { command rm -rf "$ZSH/log/update.lock" # Restart the zsh session if there were changes - if [[ "$1" != --unattended && "$(cd "$ZSH"; git rev-parse HEAD)" != "$last_commit" ]]; then + if [[ "$1" != --unattended && "$(builtin cd -q "$ZSH"; git rev-parse HEAD)" != "$last_commit" ]]; then # Old zsh versions don't have ZSH_ARGZERO local zsh="${ZSH_ARGZERO:-${functrace[-1]%:*}}" # Check whether to run a login shell @@ -787,7 +787,7 @@ function _omz::update { function _omz::version { ( - cd "$ZSH" + builtin cd -q "$ZSH" # Get the version name: # 1) try tag-like version diff --git a/tools/check_for_upgrade.sh b/tools/check_for_upgrade.sh index 729d8ecb5..3f6d35c3e 100644 --- a/tools/check_for_upgrade.sh +++ b/tools/check_for_upgrade.sh @@ -36,11 +36,11 @@ function current_epoch() { function is_update_available() { local branch - branch=${"$(cd "$ZSH"; git config --local oh-my-zsh.branch)":-master} + branch=${"$(cd -q "$ZSH"; git config --local oh-my-zsh.branch)":-master} local remote remote_url remote_repo - remote=${"$(cd "$ZSH"; git config --local oh-my-zsh.remote)":-origin} - remote_url=$(cd "$ZSH"; git config remote.$remote.url) + remote=${"$(cd -q "$ZSH"; git config --local oh-my-zsh.remote)":-origin} + remote_url=$(cd -q "$ZSH"; git config remote.$remote.url) local repo case "$remote_url" in @@ -58,7 +58,7 @@ function is_update_available() { # Get local HEAD. If this fails assume there are updates local local_head - local_head=$(cd "$ZSH"; git rev-parse $branch 2>/dev/null) || return 0 + local_head=$(cd -q "$ZSH"; git rev-parse $branch 2>/dev/null) || return 0 # Get remote HEAD. If no suitable command is found assume there are updates # On any other error, skip the update (connection may be down) @@ -136,7 +136,7 @@ function update_ohmyzsh() { fi # Test if Oh My Zsh directory is a git repository - if ! (cd "$ZSH" && LANG= git rev-parse &>/dev/null); then + if ! (cd -q "$ZSH" && LANG= git rev-parse &>/dev/null); then echo >&2 "[oh-my-zsh] Can't update: not a git repository." return fi -- cgit v1.2.3-70-g09d2 From f0f42828fa6842af631cc3dbf45f5454ea88fa3c Mon Sep 17 00:00:00 2001 From: Marc Cornellà Date: Mon, 7 Feb 2022 18:58:47 +0100 Subject: feat(updater): do not update when user already typed some characters (#9699) Fixes #9699 --- tools/check_for_upgrade.sh | 41 +++++++++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 16 deletions(-) (limited to 'tools/check_for_upgrade.sh') 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 -- cgit v1.2.3-70-g09d2 From dbd92a62ce1fc25a6819ae6d0a29dc8b8ec9a7dd Mon Sep 17 00:00:00 2001 From: Marc Cornellà Date: Fri, 11 Feb 2022 10:01:48 +0100 Subject: fix(updater): do not swallow 1 character in check for user input Co-authored-by: Philippe Troin --- tools/check_for_upgrade.sh | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'tools/check_for_upgrade.sh') diff --git a/tools/check_for_upgrade.sh b/tools/check_for_upgrade.sh index 4484df4fe..33f30c85a 100644 --- a/tools/check_for_upgrade.sh +++ b/tools/check_for_upgrade.sh @@ -89,6 +89,23 @@ function update_ohmyzsh() { fi } +function has_typed_input() { + # Created by Philippe Troin + # https://zsh.org/mla/users/2022/msg00062.html + emulate -L zsh + zmodload zsh/zselect + + { + local termios=$(stty --save) + stty -icanon + + zselect -t 0 -r 0 + return $? + } always { + stty $termios + } +} + () { emulate -L zsh @@ -159,7 +176,7 @@ function update_ohmyzsh() { fi # If user has typed input, show reminder and exit - if read -t -k 1; then + if has_typed_input; then echo echo "[oh-my-zsh] It's time to update! You can do that by running \`omz update\`" return 0 -- cgit v1.2.3-70-g09d2 From 69e29378915d53655d8fa8dc181b6cf526754569 Mon Sep 17 00:00:00 2001 From: Marc Cornellà Date: Fri, 11 Feb 2022 19:51:52 +0100 Subject: fix(updater): fix input check on non-interactive runs Reference: https://www.zsh.org/mla/users/2022/msg00067.html --- tools/check_for_upgrade.sh | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'tools/check_for_upgrade.sh') diff --git a/tools/check_for_upgrade.sh b/tools/check_for_upgrade.sh index 33f30c85a..a36aecb84 100644 --- a/tools/check_for_upgrade.sh +++ b/tools/check_for_upgrade.sh @@ -95,13 +95,21 @@ function has_typed_input() { emulate -L zsh zmodload zsh/zselect + # Back up stty settings prior to disabling canonical mode + # Consider that no input can be typed if stty fails + # (this might happen if stdin is not a terminal) + local termios + termios=$(stty --save 2>/dev/null) || return 1 { - local termios=$(stty --save) + # Disable canonical mode so that typed input counts + # regardless of whether Enter was pressed stty -icanon + # Poll stdin (fd 0) for data ready to be read zselect -t 0 -r 0 return $? } always { + # Restore stty settings stty $termios } } -- cgit v1.2.3-70-g09d2