diff options
author | Robby Russell <robby@planetargon.com> | 2015-09-19 08:45:43 -0700 |
---|---|---|
committer | Robby Russell <robby@planetargon.com> | 2015-09-19 08:45:43 -0700 |
commit | cc53e4cb9945dca873a5f62647db1b29973c6e34 (patch) | |
tree | 1be0f6729970cce97f5a91d511facb35d72b30a0 /plugins | |
parent | 56cdec75348cc7c33f54c5441884238c25a6597b (diff) | |
parent | c7d782f1ab2488ff0e44c2d72d9b81ea24b3195c (diff) | |
download | zsh-cc53e4cb9945dca873a5f62647db1b29973c6e34.tar.gz zsh-cc53e4cb9945dca873a5f62647db1b29973c6e34.tar.bz2 zsh-cc53e4cb9945dca873a5f62647db1b29973c6e34.zip |
Merge pull request #2471 from phstc/capistrano-multistage
Adds support to capistrano multistage completion
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/capistrano/_capistrano | 53 | ||||
-rw-r--r-- | plugins/capistrano/capistrano.plugin.zsh | 11 |
2 files changed, 57 insertions, 7 deletions
diff --git a/plugins/capistrano/_capistrano b/plugins/capistrano/_capistrano index 3cadf3d54..e6e71ffcc 100644 --- a/plugins/capistrano/_capistrano +++ b/plugins/capistrano/_capistrano @@ -1,10 +1,49 @@ -#compdef cap +#compdef shipit #autoload -if [[ -f config/deploy.rb || -f Capfile ]]; then - if [[ ! -f .cap_tasks~ || config/deploy.rb -nt .cap_tasks~ ]]; then - echo "\nGenerating .cap_tasks~..." > /dev/stderr - cap -v --tasks | grep '#' | cut -d " " -f 2 > .cap_tasks~ +# Added `shipit` because `cap` is a reserved word. `cap` completion doesn't work. +# http://zsh.sourceforge.net/Doc/Release/Zsh-Modules.html#The-zsh_002fcap-Module + +local curcontext="$curcontext" state line ret=1 +local -a _configs + +_arguments -C \ + '1: :->cmds' \ + '2:: :->args' && ret=0 + +_cap_tasks() { + if [[ -f config/deploy.rb || -f Capfile ]]; then + if [[ ! -f .cap_tasks~ ]]; then + shipit -v --tasks | sed 's/\(\[\)\(.*\)\(\]\)/\2:/' | awk '{command=$2; $1=$2=$3=""; gsub(/^[ \t\r\n]+/, "", $0); gsub(":", "\\:", command); print command"["$0"]"}' > .cap_tasks~ + fi + + OLD_IFS=$IFS + IFS=$'\n' + _values 'cap commands' $(< .cap_tasks~) + IFS=$OLD_IFS + # zmodload zsh/mapfile + # _values ${(f)mapfile[.cap_tasks~]} fi - compadd `cat .cap_tasks~` -fi +} + +_cap_stages() { + compadd $(find config/deploy -name \*.rb | cut -d/ -f3 | sed s:.rb::g) +} + +case $state in + cmds) + # check if it uses multistage + if [[ -d config/deploy ]]; then + _cap_stages + else + _cap_tasks + fi + ret=0 + ;; + args) + _cap_tasks + ret=0 + ;; +esac + +return ret diff --git a/plugins/capistrano/capistrano.plugin.zsh b/plugins/capistrano/capistrano.plugin.zsh new file mode 100644 index 000000000..c85eb474c --- /dev/null +++ b/plugins/capistrano/capistrano.plugin.zsh @@ -0,0 +1,11 @@ +# Added `shipit` because `cap` is a reserved word. `cap` completion doesn't work. +# http://zsh.sourceforge.net/Doc/Release/Zsh-Modules.html#The-zsh_002fcap-Module + +func shipit() { + if [ -f Gemfile ] + then + bundle exec cap $* + else + cap $* + fi +} |