Call subcommands from zsh completion

This change is inspired by the way that the git zsh completions work by foisting
the responsibility for sub commands onto the command themselves.
It is paired with another change that takes the oh-my-zsh brew cask plugin and
makes it into a first class completion rather than it overriding this.

This change requires fixes in brew, oh-my-zsh and the zsh-completions, and will
likely cause the brew cask completions to break until these have been fully
accepted into each project.
This commit is contained in:
Joshua McKinney 2016-06-27 14:42:46 -05:00
parent fc85a6fab6
commit bf4f337903

View File

@ -2,8 +2,6 @@
#autoload #autoload
# Brew ZSH completion function # Brew ZSH completion function
#
# altered from _fink
_brew_all_formulae() { _brew_all_formulae() {
formulae=(`brew search`) formulae=(`brew search`)
@ -29,6 +27,12 @@ _brew_outdated_formulae() {
outdated_formulae=(`brew outdated`) outdated_formulae=(`brew outdated`)
} }
__brew_command() {
local command="$1"
local completion_func="_brew_${command//-/_}"
declare -f "$completion_func" >/dev/null && "$completion_func" && return
}
local -a _1st_arguments local -a _1st_arguments
_1st_arguments=( _1st_arguments=(
'audit:check formulae for Homebrew coding style' 'audit:check formulae for Homebrew coding style'
@ -95,7 +99,8 @@ if (( CURRENT == 1 )); then
return return
fi fi
case "$words[1]" in local command="$words[1]"
case "$command" in
analytics) compadd on off state regenerate-uuid ;; analytics) compadd on off state regenerate-uuid ;;
install|reinstall|audit|home|homepage|log|info|abv|uses|cat|deps|desc|edit|options|switch) install|reinstall|audit|home|homepage|log|info|abv|uses|cat|deps|desc|edit|options|switch)
_brew_all_formulae _brew_all_formulae
@ -145,4 +150,6 @@ case "$words[1]" in
_brew_outdated_formulae _brew_outdated_formulae
_wanted outdated_formulae expl 'outdated formulae' compadd -a outdated_formulae _wanted outdated_formulae expl 'outdated formulae' compadd -a outdated_formulae
fi ;; fi ;;
*)
__brew_command "$command" ;;
esac esac