Parent directory

_capistrano

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