_wd.sh 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #compdef wd.sh
  2. zstyle ":completion:*:descriptions" format "%B%d%b"
  3. CONFIG=$HOME/.warprc
  4. local -a main_commands
  5. main_commands=(
  6. add:'Adds the current working directory to your warp points'
  7. #add'\!':'Overwrites existing warp point' # TODO: Fix
  8. rm:'Removes the given warp point'
  9. ls:'Outputs all stored warp points'
  10. show:'Outputs warp points to current directory'
  11. )
  12. local -a points
  13. while read line
  14. do
  15. points+=$(awk "{ gsub(/\/Users\/$USER|\/home\/$USER/,\"~\"); print }" <<< $line)
  16. done < $CONFIG
  17. _wd()
  18. {
  19. # init variables
  20. local curcontext="$curcontext" state line
  21. typeset -A opt_args
  22. # init state
  23. _arguments \
  24. '1: :->command' \
  25. '2: :->argument'
  26. case $state in
  27. command)
  28. compadd "$@" add rm ls show
  29. _describe -t warp-points 'Warp points:' points && ret=0
  30. ;;
  31. argument)
  32. case $words[2] in
  33. rm|add!)
  34. _describe -t warp-points 'warp points' points && ret=0
  35. ;;
  36. *)
  37. esac
  38. esac
  39. }
  40. _wd "$@"