1 # enables cycling through the directory stack using
2 # Ctrl+Shift+Left/Right
4 # left/right direction follows the order in which directories
5 # were visited, like left/right arrows do in a browser
7 # NO_PUSHD_MINUS syntax:
8 # pushd +N: start counting from left of `dirs' output
9 # pushd -N: start counting from right of `dirs' output
12 setopt localoptions nopushdminus
13 [[ ${#dirstack} -eq 0 ]] && return 1
15 while ! builtin pushd -q $1 &>/dev/null; do
16 # We found a missing directory: pop it out of the dir stack
19 # Stop trying if there are no more directories in the dir stack
20 [[ ${#dirstack} -eq 0 ]] && return 1
24 insert-cycledleft () {
25 switch-to-dir +1 || return
28 for fn (chpwd $chpwd_functions precmd $precmd_functions); do
29 (( $+functions[$fn] )) && $fn
33 zle -N insert-cycledleft
35 insert-cycledright () {
36 switch-to-dir -0 || return
39 for fn (chpwd $chpwd_functions precmd $precmd_functions); do
40 (( $+functions[$fn] )) && $fn
44 zle -N insert-cycledright
47 # These sequences work for xterm, Apple Terminal.app, and probably others.
48 # Not for rxvt-unicode, but it doesn't seem differentiate Ctrl-Shift-Arrow
49 # from plain Shift-Arrow, at least by default.
50 # iTerm2 does not have these key combinations defined by default; you will need
51 # to add them under "Keys" in your profile if you want to use this. You can do
52 # this conveniently by loading the "xterm with Numeric Keypad" preset.
53 bindkey "\e[1;6D" insert-cycledleft
54 bindkey "\e[1;6C" insert-cycledright