1
0
Fork 0
mirror of https://github.com/ohmyzsh/ohmyzsh.git synced 2024-11-11 00:10:08 +00:00

Merge pull request #2471 from phstc/capistrano-multistage

Adds support to capistrano multistage completion
This commit is contained in:
Robby Russell 2015-09-19 08:45:43 -07:00
commit cc53e4cb99
2 changed files with 57 additions and 7 deletions

View file

@ -1,10 +1,49 @@
#compdef cap #compdef shipit
#autoload #autoload
# 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 config/deploy.rb || -f Capfile ]]; then
if [[ ! -f .cap_tasks~ || config/deploy.rb -nt .cap_tasks~ ]]; then if [[ ! -f .cap_tasks~ ]]; then
echo "\nGenerating .cap_tasks~..." > /dev/stderr shipit -v --tasks | sed 's/\(\[\)\(.*\)\(\]\)/\2:/' | awk '{command=$2; $1=$2=$3=""; gsub(/^[ \t\r\n]+/, "", $0); gsub(":", "\\:", command); print command"["$0"]"}' > .cap_tasks~
cap -v --tasks | grep '#' | cut -d " " -f 2 > .cap_tasks~
fi fi
compadd `cat .cap_tasks~`
OLD_IFS=$IFS
IFS=$'\n'
_values 'cap commands' $(< .cap_tasks~)
IFS=$OLD_IFS
# zmodload zsh/mapfile
# _values ${(f)mapfile[.cap_tasks~]}
fi 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

View file

@ -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
}