ac3b345365354252b7c264d5ff4fe6957c11798d

Author
Marc Cornellà <marc.cornella@live.com>
Committer
GitHub <noreply@github.com>
Date

Message

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
12 
13 	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
16 
17 		# 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 }
22 
23 insert-cycledleft () {
24-	emulate -L zsh
25-	setopt nopushdminus
26+	switch-to-dir +1 || return
27 
28-	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
36 
37 insert-cycledright () {
38-	emulate -L zsh
39-	setopt nopushdminus
40+	switch-to-dir -0 || return
41 
42-	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