diff --git a/plugins/dircycle/dircycle.plugin.zsh b/plugins/dircycle/dircycle.plugin.zsh index 8a406b54d..2f32277cf 100644 --- a/plugins/dircycle/dircycle.plugin.zsh +++ b/plugins/dircycle/dircycle.plugin.zsh @@ -8,11 +8,21 @@ # pushd +N: start counting from left of `dirs' output # pushd -N: start counting from right of `dirs' output +switch-to-dir () { + while ! builtin pushd -q $1 &>/dev/null; do + # We found a missing directory: pop it out of the dir stack + builtin popd -q $1 + + # Stop trying if there are no more directories in the dir stack + [[ ${#dirstack} -eq 0 ]] && break + done +} + insert-cycledleft () { emulate -L zsh setopt nopushdminus - builtin pushd -q +1 &>/dev/null || true + switch-to-dir +1 zle reset-prompt } zle -N insert-cycledleft @@ -21,7 +31,7 @@ insert-cycledright () { emulate -L zsh setopt nopushdminus - builtin pushd -q -0 &>/dev/null || true + switch-to-dir -0 zle reset-prompt } zle -N insert-cycledright