251bc2d38050f54f85f730bb9e0dd1399e5c3067

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

Message

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.

Diff

 1diff --git a/plugins/dircycle/dircycle.plugin.zsh b/plugins/dircycle/dircycle.plugin.zsh
 2index 8a406b54d772af4bc955b8f348edcc0a40e7454e..2f32277cf03dceab526b7da6238523c9d6c448f7 100644
 3--- a/plugins/dircycle/dircycle.plugin.zsh
 4+++ b/plugins/dircycle/dircycle.plugin.zsh
 5@@ -8,11 +8,21 @@
 6 #  pushd +N: start counting from left of `dirs' output
 7 #  pushd -N: start counting from right of `dirs' output
 8 
 9+switch-to-dir () {
10+	while ! builtin pushd -q $1 &>/dev/null; do
11+		# We found a missing directory: pop it out of the dir stack
12+		builtin popd -q $1
13+
14+		# Stop trying if there are no more directories in the dir stack
15+		[[ ${#dirstack} -eq 0 ]] && break
16+	done
17+}
18+
19 insert-cycledleft () {
20 	emulate -L zsh
21 	setopt nopushdminus
22 
23-	builtin pushd -q +1 &>/dev/null || true
24+	switch-to-dir +1
25 	zle reset-prompt
26 }
27 zle -N insert-cycledleft
28@@ -21,7 +31,7 @@ insert-cycledright () {
29 	emulate -L zsh
30 	setopt nopushdminus
31 
32-	builtin pushd -q -0 &>/dev/null || true
33+	switch-to-dir -0
34 	zle reset-prompt
35 }
36 zle -N insert-cycledright