Skip to content

Instantly share code, notes, and snippets.

@webframp
Created June 18, 2016 17:52
Show Gist options
  • Save webframp/875598e8d1ce422607b5e913079a68b5 to your computer and use it in GitHub Desktop.
Save webframp/875598e8d1ce422607b5e913079a68b5 to your computer and use it in GitHub Desktop.
sort of functional kitchen completion
#compdef kitchen
#autoload
# kitchen zsh completion
local -a _1st_arguments
_1st_arguments=(
'console:Kitchen console!'
'converge:[(all|<REGEX>)] [opts] Converge one or more instances'
'create:[(all|<REGEX>)] [opts] Create one or more instances'
'destroy:[(all|<REGEX>)] [opts] Destroy one or more instances'
'help:[TASK] Describe available tasks or one specific task'
'init: Adds some configuration to your cookbook so Kitchen can rock'
'list:[(all|<REGEX>)] [opts] List all instances'
'login:(['REGEX']| [INSTANCE]) Log in to one instance'
'new_plugin:[NAME] Generate a new Kitchen Driver plugin gem project'
'setup:[(all|<REGEX>)] [opts] Setup one or more instances'
'test:[(all|<REGEX>)]'
)
__task_list ()
{
local expl
declare -a tasks
tasks=(console converge create destroy help init list login new_plugin setup test)
_wanted tasks expl 'help' compadd $tasks
}
__box_list ()
{
_wanted application expl 'command' compadd $(command grep 'box:' $PWD/.kitchen.yml 2>/dev/null| awk '{print $2}')
}
__plugin_name ()
{
echo "Any valid name"
}
local expl
local -a boxes installed_boxes
local curcontext="$curcontext" state line
typeset -A opt_args
# FIX what's this doing?
_arguments -C \
':command:->command' \
'*::options:->options'
case $state in
(command)
_describe -t commands "kitchen subcommand" _1st_arguments
return
;;
(options)
case $line[1] in
(help)
_arguments ':feature:__task_list'
;;
(init)
# no args
;;
(new_plugin)
__plugin_name
;;
(console|converge|create|destroy|list|login|setup|test)
_arguments ':feature:__box_list'
esac
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment