dircycle.plugin.zsh 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. # NO_PUSHD_MINUS syntax:
  7. # pushd +N: start counting from left of `dirs' output
  8. # pushd -N: start counting from right of `dirs' output
  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. # Stop trying if there are no more directories in the dir stack
  14. [[ ${#dirstack} -eq 0 ]] && break
  15. done
  16. }
  17. insert-cycledleft () {
  18. emulate -L zsh
  19. setopt nopushdminus
  20. switch-to-dir +1
  21. zle reset-prompt
  22. }
  23. zle -N insert-cycledleft
  24. insert-cycledright () {
  25. emulate -L zsh
  26. setopt nopushdminus
  27. switch-to-dir -0
  28. zle reset-prompt
  29. }
  30. zle -N insert-cycledright
  31. # These sequences work for xterm, Apple Terminal.app, and probably others.
  32. # Not for rxvt-unicode, but it doesn't seem differentiate Ctrl-Shift-Arrow
  33. # from plain Shift-Arrow, at least by default.
  34. # iTerm2 does not have these key combinations defined by default; you will need
  35. # to add them under "Keys" in your profile if you want to use this. You can do
  36. # this conveniently by loading the "xterm with Numeric Keypad" preset.
  37. bindkey "\e[1;6D" insert-cycledleft
  38. bindkey "\e[1;6C" insert-cycledright