dircycle.plugin.zsh 1.3 KB

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