dircycle: trigger appropriate hooks after directory change (#7161)
This commit triggers precmd and chpwd hook functions iff we changed directory.
This has the same behavior as zsh's hook function execution, which tries to run
the functions in the order specified and silently ignores any function that
does not exist.
See http://zsh.sourceforge.net/Doc/Release/Functions.html#Hook-Functions
Also moved duplicate nopushdminus logic to the `switch-to-dir` function.
Diff
1diff --git a/plugins/dircycle/dircycle.plugin.zsh b/plugins/dircycle/dircycle.plugin.zsh
2index 8c58cab4c7b312ba7b3c8be9f3389ff9143163bb..bb69f6b3fd7bb3a647aeb10310e98b39d6021c9a 100644
3--- a/plugins/dircycle/dircycle.plugin.zsh
4+++ b/plugins/dircycle/dircycle.plugin.zsh
5@@ -9,31 +9,36 @@
6 # pushd -N: start counting from right of `dirs' output
7 8 switch-to-dir () {
9- [[ ${#dirstack} -eq 0 ]] && return
10+ setopt localoptions nopushdminus
11+ [[ ${#dirstack} -eq 0 ]] && return 1
1213 while ! builtin pushd -q $1 &>/dev/null; do
14 # We found a missing directory: pop it out of the dir stack
15 builtin popd -q $1
1617 # Stop trying if there are no more directories in the dir stack
18- [[ ${#dirstack} -eq 0 ]] && break
19+ [[ ${#dirstack} -eq 0 ]] && return 1
20 done
21 }
2223 insert-cycledleft () {
24- emulate -L zsh
25- setopt nopushdminus
26+ switch-to-dir +1 || return
2728- switch-to-dir +1
29+ local fn
30+ for fn (chpwd $chpwd_functions precmd $precmd_functions); do
31+ (( $+functions[$fn] )) && $fn
32+ done
33 zle reset-prompt
34 }
35 zle -N insert-cycledleft
3637 insert-cycledright () {
38- emulate -L zsh
39- setopt nopushdminus
40+ switch-to-dir -0 || return
4142- switch-to-dir -0
43+ local fn
44+ for fn (chpwd $chpwd_functions precmd $precmd_functions); do
45+ (( $+functions[$fn] )) && $fn
46+ done
47 zle reset-prompt
48 }
49 zle -N insert-cycledright