mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2024-11-11 00:10:08 +00:00
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.
This commit is contained in:
parent
a8e69686aa
commit
ac3b345365
1 changed files with 13 additions and 8 deletions
|
@ -9,31 +9,36 @@
|
||||||
# pushd -N: start counting from right of `dirs' output
|
# pushd -N: start counting from right of `dirs' output
|
||||||
|
|
||||||
switch-to-dir () {
|
switch-to-dir () {
|
||||||
[[ ${#dirstack} -eq 0 ]] && return
|
setopt localoptions nopushdminus
|
||||||
|
[[ ${#dirstack} -eq 0 ]] && return 1
|
||||||
|
|
||||||
while ! builtin pushd -q $1 &>/dev/null; do
|
while ! builtin pushd -q $1 &>/dev/null; do
|
||||||
# We found a missing directory: pop it out of the dir stack
|
# We found a missing directory: pop it out of the dir stack
|
||||||
builtin popd -q $1
|
builtin popd -q $1
|
||||||
|
|
||||||
# Stop trying if there are no more directories in the dir stack
|
# Stop trying if there are no more directories in the dir stack
|
||||||
[[ ${#dirstack} -eq 0 ]] && break
|
[[ ${#dirstack} -eq 0 ]] && return 1
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
insert-cycledleft () {
|
insert-cycledleft () {
|
||||||
emulate -L zsh
|
switch-to-dir +1 || return
|
||||||
setopt nopushdminus
|
|
||||||
|
|
||||||
switch-to-dir +1
|
local fn
|
||||||
|
for fn (chpwd $chpwd_functions precmd $precmd_functions); do
|
||||||
|
(( $+functions[$fn] )) && $fn
|
||||||
|
done
|
||||||
zle reset-prompt
|
zle reset-prompt
|
||||||
}
|
}
|
||||||
zle -N insert-cycledleft
|
zle -N insert-cycledleft
|
||||||
|
|
||||||
insert-cycledright () {
|
insert-cycledright () {
|
||||||
emulate -L zsh
|
switch-to-dir -0 || return
|
||||||
setopt nopushdminus
|
|
||||||
|
|
||||||
switch-to-dir -0
|
local fn
|
||||||
|
for fn (chpwd $chpwd_functions precmd $precmd_functions); do
|
||||||
|
(( $+functions[$fn] )) && $fn
|
||||||
|
done
|
||||||
zle reset-prompt
|
zle reset-prompt
|
||||||
}
|
}
|
||||||
zle -N insert-cycledright
|
zle -N insert-cycledright
|
||||||
|
|
Loading…
Reference in a new issue