_wd.sh 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. 'ls:Outputs all stored warp points'
  18. 'show:Outputs all warp points that point to the current directory or shows a specific target directory for a point'
  19. 'show:Outputs all warp points that point to the current directory or shows a specific target directory for a point'
  20. 'help:Show this extremely helpful text'
  21. '..:Go back to last directory'
  22. )
  23. _arguments -C \
  24. '1: :->first_arg' \
  25. '2: :->second_arg' && ret=0
  26. case $state in
  27. first_arg)
  28. _describe -t warp_points "Warp points" warp_points && ret=0
  29. _describe -t commands "Commands" commands && ret=0
  30. ;;
  31. second_arg)
  32. case $words[2] in
  33. add\!|rm)
  34. _describe -t points "Warp points" warp_points && ret=0
  35. ;;
  36. add)
  37. _message 'Write the name of your warp point' && ret=0
  38. ;;
  39. show)
  40. _describe -t points "Warp points" warp_points && ret=0
  41. ;;
  42. esac
  43. ;;
  44. esac
  45. return $ret
  46. }
  47. _wd "$@"
  48. # Local Variables:
  49. # mode: Shell-Script
  50. # sh-indentation: 2
  51. # indent-tabs-mode: nil
  52. # sh-basic-offset: 2
  53. # End:
  54. # vim: ft=zsh sw=2 ts=2 et