summaryrefslogtreecommitdiff
path: root/plugins/dircycle/dircycle.plugin.zsh
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/dircycle/dircycle.plugin.zsh')
-rw-r--r--plugins/dircycle/dircycle.plugin.zsh45
1 files changed, 31 insertions, 14 deletions
diff --git a/plugins/dircycle/dircycle.plugin.zsh b/plugins/dircycle/dircycle.plugin.zsh
index 1e31105b1..bb69f6b3f 100644
--- a/plugins/dircycle/dircycle.plugin.zsh
+++ b/plugins/dircycle/dircycle.plugin.zsh
@@ -8,30 +8,47 @@
# pushd +N: start counting from left of `dirs' output
# pushd -N: start counting from right of `dirs' output
+switch-to-dir () {
+ setopt localoptions nopushdminus
+ [[ ${#dirstack} -eq 0 ]] && return 1
+
+ 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 ]] && return 1
+ done
+}
+
insert-cycledleft () {
- emulate -L zsh
- setopt nopushdminus
+ switch-to-dir +1 || return
- builtin pushd -q +1 &>/dev/null || true
+ local fn
+ for fn (chpwd $chpwd_functions precmd $precmd_functions); do
+ (( $+functions[$fn] )) && $fn
+ done
zle reset-prompt
}
zle -N insert-cycledleft
insert-cycledright () {
- emulate -L zsh
- setopt nopushdminus
+ switch-to-dir -0 || return
- builtin pushd -q -0 &>/dev/null || true
+ local fn
+ for fn (chpwd $chpwd_functions precmd $precmd_functions); do
+ (( $+functions[$fn] )) && $fn
+ done
zle reset-prompt
}
zle -N insert-cycledright
-# add key bindings for iTerm2
-if [[ "$TERM_PROGRAM" == "iTerm.app" ]]; then
- bindkey "^[[1;6D" insert-cycledleft
- bindkey "^[[1;6C" insert-cycledright
-else
- bindkey "\e[1;6D" insert-cycledleft
- bindkey "\e[1;6C" insert-cycledright
-fi \ No newline at end of file
+# These sequences work for xterm, Apple Terminal.app, and probably others.
+# Not for rxvt-unicode, but it doesn't seem differentiate Ctrl-Shift-Arrow
+# from plain Shift-Arrow, at least by default.
+# iTerm2 does not have these key combinations defined by default; you will need
+# to add them under "Keys" in your profile if you want to use this. You can do
+# this conveniently by loading the "xterm with Numeric Keypad" preset.
+bindkey "\e[1;6D" insert-cycledleft
+bindkey "\e[1;6C" insert-cycledright