Use safer append to hook function arrays (#8406)

Use add-zsh-hook to add functions to hooks. That way they won't be added again
when doing `source ~/.zshrc` multiple times.

Co-authored-by: Marc Cornellà <marc.cornella@live.com>
This commit is contained in:
Jacob Tomaw 2019-11-19 12:47:12 -05:00 committed by Marc Cornellà
commit 1ba0af650a
12 changed files with 29 additions and 23 deletions

View file

@ -2,7 +2,8 @@
typeset -g ZSH_LAST_WORKING_DIRECTORY
# Updates the last directory once directory is changed
chpwd_functions+=(chpwd_last_working_dir)
autoload -U add-zsh-hook
add-zsh-hook chpwd chpwd_last_working_dir
chpwd_last_working_dir() {
if [ "$ZSH_SUBSHELL" = 0 ]; then
local cache_file="$ZSH_CACHE_DIR/last-working-dir"