diff options
author | Marc Cornellà <hello@mcornella.com> | 2021-12-26 18:58:22 +0100 |
---|---|---|
committer | Marc Cornellà <hello@mcornella.com> | 2021-12-26 18:58:54 +0100 |
commit | 70dfb6ef92f3bedc460e300e94e3456942ff328c (patch) | |
tree | 3f919ddc27ab7c635293b264d6ee688f8cfed750 /plugins/composer | |
parent | 5f6b0ac7fbfbb0e25d0d691efa1bf676ac9f6962 (diff) | |
download | zsh-70dfb6ef92f3bedc460e300e94e3456942ff328c.tar.gz zsh-70dfb6ef92f3bedc460e300e94e3456942ff328c.tar.bz2 zsh-70dfb6ef92f3bedc460e300e94e3456942ff328c.zip |
refactor(composer): improve completion and use official Zsh completion if available
Diffstat (limited to 'plugins/composer')
-rw-r--r-- | plugins/composer/composer.plugin.zsh | 34 |
1 files changed, 25 insertions, 9 deletions
diff --git a/plugins/composer/composer.plugin.zsh b/plugins/composer/composer.plugin.zsh index ba29503e4..f2076c220 100644 --- a/plugins/composer/composer.plugin.zsh +++ b/plugins/composer/composer.plugin.zsh @@ -1,18 +1,34 @@ -_composer () { +## Basic Composer command completion +# Since Zsh 5.7, an improved composer command completion is provided +if ! is-at-least 5.7; then + _composer () { local curcontext="$curcontext" state line typeset -A opt_args - _arguments \ - '*:: :->subcmds' + _arguments '*:: :->subcmds' - if (( CURRENT == 1 )) || ( ((CURRENT == 2)) && [ "$words[1]" = "global" ] ) ; then - compadd $(_composer_get_command_list) + if (( CURRENT == 1 )) || ( (( CURRENT == 2 )) && [[ "$words[1]" = "global" ]] ); then + # Command list + local -a subcmds + subcmds=("${(@f)"$($_comp_command1 --no-ansi 2>/dev/null | awk ' + /Available commands/{ r=1 } + r == 1 && /^[ \t]*[a-z]+/{ + gsub(/^[ \t]+/, "") + gsub(/ +/, ":") + print $0 + } + ')"}") + _describe -t commands 'composer command' subcmds else - compadd $(_composer_get_required_list) + # Required list + compadd $($_comp_command1 show -s --no-ansi 2>/dev/null \ + | sed '1,/requires/d' \ + | awk 'NF > 0 && !/^requires \(dev\)/{ print $1 }') fi -} + } -compdef _composer composer -compdef _composer composer.phar + compdef _composer composer + compdef _composer composer.phar +fi ## Aliases |