]> src.twobees.de Git - dotfiles.git/blob - stow/oh-my-zsh/.oh-my-zsh/plugins/dircycle/dircycle.plugin.zsh
bb69f6b3fd7bb3a647aeb10310e98b39d6021c9a
[dotfiles.git] / stow / oh-my-zsh / .oh-my-zsh / plugins / dircycle / dircycle.plugin.zsh
1 # enables cycling through the directory stack using
2 # Ctrl+Shift+Left/Right
3 #
4 # left/right direction follows the order in which directories
5 # were visited, like left/right arrows do in a browser
6
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
10
11 switch-to-dir () {
12         setopt localoptions nopushdminus
13         [[ ${#dirstack} -eq 0 ]] && return 1
14
15         while ! builtin pushd -q $1 &>/dev/null; do
16                 # We found a missing directory: pop it out of the dir stack
17                 builtin popd -q $1
18
19                 # Stop trying if there are no more directories in the dir stack
20                 [[ ${#dirstack} -eq 0 ]] && return 1
21         done
22 }
23
24 insert-cycledleft () {
25         switch-to-dir +1 || return
26
27         local fn
28         for fn (chpwd $chpwd_functions precmd $precmd_functions); do
29                 (( $+functions[$fn] )) && $fn
30         done
31         zle reset-prompt
32 }
33 zle -N insert-cycledleft
34
35 insert-cycledright () {
36         switch-to-dir -0 || return
37
38         local fn
39         for fn (chpwd $chpwd_functions precmd $precmd_functions); do
40                 (( $+functions[$fn] )) && $fn
41         done
42         zle reset-prompt
43 }
44 zle -N insert-cycledright
45
46
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