From 3df7a304c48e6e234e962227d966a4eb0cfa9afe Mon Sep 17 00:00:00 2001 From: bretello Date: Sat, 26 Nov 2022 00:48:21 +0100 Subject: [PATCH] zsh: make update mechanism less annoying move .zsh file to extras/ so that it doesn't get sourced twice because of the ZSH_CUSTOM bug --- brethil_dotfile.sh | 7 ++++--- .../check_for_update.zsh | 15 +++++---------- 2 files changed, 9 insertions(+), 13 deletions(-) rename check_for_update.zsh => extras/check_for_update.zsh (89%) diff --git a/brethil_dotfile.sh b/brethil_dotfile.sh index 0df8926..1274de4 100755 --- a/brethil_dotfile.sh +++ b/brethil_dotfile.sh @@ -1,9 +1,6 @@ # vim:ft=zsh ts=2 sw=2 sts=2 export LANG=en_US.UTF-8 -# Set DISABLE_DOTFILES_AUTOUPDATE=true to disable updates -source "${DOTFILES}/check_for_update.zsh" - # theme-related variables export ZSH_CUSTOM="$DOTFILES" export ZSH_THEME="brethil" @@ -127,3 +124,7 @@ test -f "${ssh_file}" && source "${ssh_file}" export PATH=$PATH:$HOME/bin autoload -U compinit && compinit +autoload -U bashcompinit && bashcompinit + +# Set DISABLE_DOTFILES_AUTOUPDATE=true to disable updates +source "${DOTFILES}/extras/check_for_update.zsh" diff --git a/check_for_update.zsh b/extras/check_for_update.zsh similarity index 89% rename from check_for_update.zsh rename to extras/check_for_update.zsh index c6b16be..47406ef 100755 --- a/check_for_update.zsh +++ b/extras/check_for_update.zsh @@ -42,8 +42,6 @@ function update_dotfiles() { return; fi - emulate -L zsh - local epoch_target mtime option LAST_EPOCH # Remove lock directory if older than a day @@ -65,8 +63,9 @@ function update_dotfiles() { # assumed to have been handled, and execution continues normally. Otherwise, the shell # will behave as interrupted except that the return status of the trap is retained. trap " - unset -f current_epoch _update_dotfiles_update update_dotfiles - command rm -rf '$DOTFILES/update.lock' + unset -f current_epoch _update_dotfiles_update update_dotfiles &>/dev/null + command rmdir '$DOTFILES/update.lock' &>/dev/null + echo return 1 " EXIT INT QUIT @@ -87,17 +86,13 @@ function update_dotfiles() { if [[ "$DISABLE_UPDATE_PROMPT" = true ]]; then update_dotfiles 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 "[brethil-dotfiles] Would you like to update? [Y/n] " read -r -k 1 option - [[ "$option" != $'\n' ]] && echo case "$option" in [yY$'\n']) update_dotfiles ;; [nN]) _update_dotfiles_update ;; + *) echo -n "[brethil dotfiles] Skipping. Update using \`dotfiles_selfupdate\`" && echo ;; esac fi } +unset -f current_epoch update_dotfiles _update_dotfiles_update