_wd.sh 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #compdef wd
  2. zstyle ':completion:*:descriptions' format '%B%d%b'
  3. zstyle ':completion::complete:wd:*:commands' group-name commands
  4. zstyle ':completion::complete:wd:*:warp_points' group-name warp_points
  5. zstyle ':completion::complete:wd::' list-grouped
  6. zmodload zsh/mapfile
  7. function _wd() {
  8. local CONFIG=$HOME/.warprc
  9. local ret=1
  10. local -a commands
  11. local -a warp_points
  12. warp_points=( "${(f)mapfile[$CONFIG]//$HOME/~}" )
  13. commands=(
  14. 'add:Adds the current working directory to your warp points'
  15. 'add!:Overwrites existing warp point'
  16. 'rm:Removes the given warp point'
  17. 'list:Outputs all stored warp points'
  18. 'ls:Show files from given warp point'
  19. 'path:Show path to given warp point'
  20. 'show:Outputs all warp points that point to the current directory or shows a specific target directory for a point'
  21. 'help:Show this extremely helpful text'
  22. 'clean:Remove points warping to nonexistent directories'
  23. 'clean!:Remove nonexistent directories without confirmation'
  24. '..:Go back to last directory'
  25. )
  26. _arguments -C \
  27. '1: :->first_arg' \
  28. '2: :->second_arg' && ret=0
  29. case $state in
  30. first_arg)
  31. _describe -t warp_points "Warp points" warp_points && ret=0
  32. _describe -t commands "Commands" commands && ret=0
  33. ;;
  34. second_arg)
  35. case $words[2] in
  36. add\!|rm)
  37. _describe -t points "Warp points" warp_points && ret=0
  38. ;;
  39. add)
  40. _message 'Write the name of your warp point' && ret=0
  41. ;;
  42. show)
  43. _describe -t points "Warp points" warp_points && ret=0
  44. ;;
  45. ls)
  46. _describe -t points "Warp points" warp_points && ret=0
  47. ;;
  48. path)
  49. _describe -t points "Warp points" warp_points && ret=0
  50. ;;
  51. esac
  52. ;;
  53. esac
  54. return $ret
  55. }
  56. _wd "$@"
  57. # Local Variables:
  58. # mode: Shell-Script
  59. # sh-indentation: 2
  60. # indent-tabs-mode: nil
  61. # sh-basic-offset: 2
  62. # End:
  63. # vim: ft=zsh sw=2 ts=2 et