diff options
author | Marc Cornellà <marc.cornella@live.com> | 2016-06-17 10:44:52 +0200 |
---|---|---|
committer | Marc Cornellà <marc.cornella@live.com> | 2016-08-22 16:57:10 +0200 |
commit | 251bc2d38050f54f85f730bb9e0dd1399e5c3067 (patch) | |
tree | ff1c857d80d6a8e555e0253aa6c9d8492f52e943 /plugins | |
parent | 7c1ca0e4d85e0de75a3eb8c23b4e799454e0f390 (diff) | |
download | zsh-251bc2d38050f54f85f730bb9e0dd1399e5c3067.tar.gz zsh-251bc2d38050f54f85f730bb9e0dd1399e5c3067.tar.bz2 zsh-251bc2d38050f54f85f730bb9e0dd1399e5c3067.zip |
dircycle: keep switch until a directory is found
This fixes the use case where a directory in the dir stack
doesn't exist anymore, so the keystroke doesn't appear to
do anything.
It will keep trying to switch to the n-est directory in the
stack until it founds an available directory or the dirstack
has no more directories to switch to.
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/dircycle/dircycle.plugin.zsh | 14 |
1 files changed, 12 insertions, 2 deletions
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 |