Skip to content

Instantly share code, notes, and snippets.

@bootleq
Created June 9, 2012 00:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bootleq/2898849 to your computer and use it in GitHub Desktop.
Save bootleq/2898849 to your computer and use it in GitHub Desktop.
zsh capistrano completeion function
#compdef cap
#autoload
# From zsh-users (https://github.com/zsh-users/zsh-completions)
# Mix with oh-my-zsh pull request #367 (https://github.com/robbyrussell/oh-my-zsh/pull/367)
_cap() {
local curcontext="$curcontext" state line cmds ret=1
local cache_file='tmp/.cap_tasks~'
# TODO use zsh built-in cache instead of cache_file
# zstyle -s ":completion:${curcontext}:" cache-policy update_policy
# [[ -z "$update_policy" ]] && zstyle ":completion:${curcontext}:" cache-policy _cap_tasks_caching_policy
_arguments -C \
{-d,--debug}'[Prompts before each remote command execution]' \
{-e,--explain}'[Displays help (if available) for the task]:task' \
{-F,--default-config}'[Always use default config, even with -f]' \
{-f,--file}'[A recipe file to load. May be given more than once]:file:_files' \
{-H,--long-help}'[Explain these options and environment variables]' \
{-h,--help}'[Display this help message]' \
{-l,--logger}'[Choose logger method. STDERR used by default]:file:_files' \
{-n,--dry-run}'[Prints out commands without running them]' \
{-p,--password}'[Immediately prompt for the password]' \
{-q,--quiet}'[Make the output as quiet as possible]' \
{-r,--preserve-roles}'[Preserve task roles]' \
{-S,--set-before}'[Set a variable before the recipes are loaded]:variable' \
{-s,--set}'[Set a variable after the recipes are loaded]:variable' \
{-T,--tasks}'[List all tasks (matching optional PATTERN) in the loaded recipe files]:pattern' \
{-t,--tool}'[Abbreviates the output of -T for tool integration]' \
{-V,--version}'[Display the Capistrano version, and exit]' \
{-v,--verbose}'[Be more verbose. May be given more than once]' \
{-X,--skip-system-config}'[Do not load the system config file (capistrano.conf)]' \
{-x,--skip-user-config}'[Do not load the user config file (.caprc)]' \
'*: :->cmds' && ret=0
# case $state in
# cmds)
# cmds=( ${(f)"$(_call_program commands cap -T 2> /dev/null | sed -e '/ # /!d; s/:/\\:/g; s/cap \([A-Za-z0-9\\:_-]*\) .*# /\1:/')"} )
# _describe -t commands 'cap command' cmds && ret=0
# ;;
# esac
if [[ -f config/deploy.rb ]]; then
if (_cap_tasks_caching_policy $cache_file); then
_call_program commands cap -T 2> /dev/null | grep '#' | cut -d " " -f 2 > $cache_file
fi
compadd `cat $cache_file`
fi
return ret
}
_cap_tasks_caching_policy() {
[[ ! -e $1 || -f config/deploy.rb && config/deploy.rb -nt "$1" ]] && return 0
return 1
}
_cap "$@"
@bootleq
Copy link
Author

bootleq commented Jun 9, 2012

filename is "_capistrano".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment