From 16ae4e127f6af2f8f3332025ce46d45ab5bcadac Mon Sep 17 00:00:00 2001 From: Pablo Cantero Date: Sun, 26 Jan 2014 10:18:04 -0200 Subject: [PATCH 1/3] Adds support capistrano multistage completion --- plugins/capistrano/_capistrano | 53 ++++++++++++++++++++---- plugins/capistrano/capistrano.plugin.zsh | 11 +++++ 2 files changed, 57 insertions(+), 7 deletions(-) create mode 100644 plugins/capistrano/capistrano.plugin.zsh diff --git a/plugins/capistrano/_capistrano b/plugins/capistrano/_capistrano index 3cadf3d5..7a74b373 100644 --- a/plugins/capistrano/_capistrano +++ b/plugins/capistrano/_capistrano @@ -1,10 +1,49 @@ -#compdef cap +#compdef xcap cap #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 `xcap` 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 + xcap -v --tasks | 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 00000000..9a4a2cc3 --- /dev/null +++ b/plugins/capistrano/capistrano.plugin.zsh @@ -0,0 +1,11 @@ +# Added `xcap` 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 xcap() { + if [ -f Gemfile ] + then + bundle exec cap $* + else + cap $* + fi +} From c9fbfc9f48b25c724265e06f0bce8d737c7ea13b Mon Sep 17 00:00:00 2001 From: Pablo Cantero Date: Fri, 4 Apr 2014 21:20:01 -0300 Subject: [PATCH 2/3] Uses `shipit` instead of `xcap` --- plugins/capistrano/_capistrano | 6 +++--- plugins/capistrano/capistrano.plugin.zsh | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/plugins/capistrano/_capistrano b/plugins/capistrano/_capistrano index 7a74b373..c181b55c 100644 --- a/plugins/capistrano/_capistrano +++ b/plugins/capistrano/_capistrano @@ -1,7 +1,7 @@ -#compdef xcap cap +#compdef shipit #autoload -# Added `xcap` because `cap` is a reserved word. `cap` completion doesn't work. +# 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 @@ -14,7 +14,7 @@ _arguments -C \ _cap_tasks() { if [[ -f config/deploy.rb || -f Capfile ]]; then if [[ ! -f .cap_tasks~ ]]; then - xcap -v --tasks | awk '{command=$2; $1=$2=$3=""; gsub(/^[ \t\r\n]+/, "", $0); gsub(":", "\\:", command); print command"["$0"]"}' > .cap_tasks~ + shipit -v --tasks | awk '{command=$2; $1=$2=$3=""; gsub(/^[ \t\r\n]+/, "", $0); gsub(":", "\\:", command); print command"["$0"]"}' > .cap_tasks~ fi OLD_IFS=$IFS diff --git a/plugins/capistrano/capistrano.plugin.zsh b/plugins/capistrano/capistrano.plugin.zsh index 9a4a2cc3..c85eb474 100644 --- a/plugins/capistrano/capistrano.plugin.zsh +++ b/plugins/capistrano/capistrano.plugin.zsh @@ -1,7 +1,7 @@ -# Added `xcap` because `cap` is a reserved word. `cap` completion doesn't work. +# 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 xcap() { +func shipit() { if [ -f Gemfile ] then bundle exec cap $* From c7d782f1ab2488ff0e44c2d72d9b81ea24b3195c Mon Sep 17 00:00:00 2001 From: Pablo Cantero Date: Thu, 3 Sep 2015 13:39:41 -0300 Subject: [PATCH 3/3] Add the update from @mtwentyman https://github.com/phstc/dotfiles/pull/1 to make it work for older versions of capistrano --- plugins/capistrano/_capistrano | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/capistrano/_capistrano b/plugins/capistrano/_capistrano index c181b55c..e6e71ffc 100644 --- a/plugins/capistrano/_capistrano +++ b/plugins/capistrano/_capistrano @@ -14,7 +14,7 @@ _arguments -C \ _cap_tasks() { if [[ -f config/deploy.rb || -f Capfile ]]; then if [[ ! -f .cap_tasks~ ]]; then - shipit -v --tasks | awk '{command=$2; $1=$2=$3=""; gsub(/^[ \t\r\n]+/, "", $0); gsub(":", "\\:", command); print command"["$0"]"}' > .cap_tasks~ + 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