my xfce4 dotfiles
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
1.1 KiB

3 years ago
  1. #compdef capit
  2. #autoload
  3. # Added `capit` because `cap` is a reserved word. `cap` completion doesn't work.
  4. # http://zsh.sourceforge.net/Doc/Release/Zsh-Modules.html#The-zsh_002fcap-Module
  5. local curcontext="$curcontext" state line ret=1
  6. local -a _configs
  7. _arguments -C \
  8. '1: :->cmds' \
  9. '2:: :->args' && ret=0
  10. _cap_tasks() {
  11. if [[ -f config/deploy.rb || -f Capfile ]]; then
  12. if [[ ! -f .cap_tasks~ ]]; then
  13. capit --tasks | sed 's/\(\[\)\(.*\)\(\]\)/\2:/' | awk '{command=$2; $1=$2=$3=""; gsub(/^[ \t\r\n]+/, "", $0); gsub(":", "\\:", command); print command"["$0"]"}' > .cap_tasks~
  14. fi
  15. OLD_IFS=$IFS
  16. IFS=$'\n'
  17. _values 'cap commands' $(< .cap_tasks~)
  18. IFS=$OLD_IFS
  19. # zmodload zsh/mapfile
  20. # _values ${(f)mapfile[.cap_tasks~]}
  21. fi
  22. }
  23. _cap_stages() {
  24. compadd $(find config/deploy -name \*.rb | cut -d/ -f3 | sed s:.rb::g)
  25. }
  26. case $state in
  27. cmds)
  28. # check if it uses multistage
  29. if [[ -d config/deploy ]]; then
  30. _cap_stages
  31. else
  32. _cap_tasks
  33. fi
  34. ret=0
  35. ;;
  36. args)
  37. _cap_tasks
  38. ret=0
  39. ;;
  40. esac
  41. return ret