_wd.sh 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. # Call `_wd()` when when trying to complete the command `wd`
  7. zmodload zsh/mapfile
  8. function _wd() {
  9. local ret=1
  10. local CONFIG=$HOME/.warprc
  11. # Stolen from
  12. # http://stackoverflow.com/questions/9000698/completion-when-program-has-sub-commands
  13. # local curcontext="$curcontext" state line
  14. # typeset -A opt_args
  15. local -a commands
  16. local -a warp_points
  17. warp_points=( "${(f)mapfile[$CONFIG]}" )
  18. # LIST="${mapfile[$FNAME]}" # Not required unless stuff uses it
  19. commands=(
  20. 'add:Adds the current working directory to your warp points'
  21. 'add!:Overwrites existing warp point'
  22. 'rm:Removes the given warp point'
  23. 'ls:Outputs all stored warp points'
  24. 'show:Outputs all warp points that point to the current directory'
  25. 'help:Show this extremely helpful text'
  26. '..:Go back to last directory'
  27. )
  28. _arguments -C \
  29. '1: :->first_arg' \
  30. '2: :->second_arg' && ret=0
  31. case $state in
  32. first_arg)
  33. _describe -t warp_points "Warp points" warp_points && ret=0
  34. _describe -t commands "Commands" commands && ret=0
  35. ;;
  36. second_arg)
  37. case $words[2] in
  38. add\!|rm)
  39. _describe -t points "Warp points" warp_points && ret=0
  40. ;;
  41. add)
  42. _message 'Write the name of your warp point' && ret=0
  43. ;;
  44. esac
  45. ;;
  46. esac
  47. return $ret
  48. }
  49. _wd "$@"
  50. # Local Variables:
  51. # mode: Shell-Script
  52. # sh-indentation: 2
  53. # indent-tabs-mode: nil
  54. # sh-basic-offset: 2
  55. # End:
  56. # vim: ft=zsh sw=2 ts=2 et