1
0
Fork 0
mirror of https://github.com/ohmyzsh/ohmyzsh.git synced 2024-11-22 13:50:09 +00:00

refactor(composer): improve completion and use official Zsh completion if available

This commit is contained in:
Marc Cornellà 2021-12-26 18:58:22 +01:00
parent 5f6b0ac7fb
commit 70dfb6ef92
No known key found for this signature in database
GPG key ID: 0314585E776A9C1B

View file

@ -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 local curcontext="$curcontext" state line
typeset -A opt_args typeset -A opt_args
_arguments \ _arguments '*:: :->subcmds'
'*:: :->subcmds'
if (( CURRENT == 1 )) || ( ((CURRENT == 2)) && [ "$words[1]" = "global" ] ) ; then if (( CURRENT == 1 )) || ( (( CURRENT == 2 )) && [[ "$words[1]" = "global" ]] ); then
compadd $(_composer_get_command_list) # 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 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 fi
} }
compdef _composer composer compdef _composer composer
compdef _composer composer.phar compdef _composer composer.phar
fi
## Aliases ## Aliases