Merge pull request #1807 from NoahGorny/cleanup/composer-completions
formatted composer completion and used helper functionpull/1835/head
commit
25c1c8978e
|
|
@ -63,6 +63,7 @@ plugins/available/xterm.plugin.bash
|
|||
completion/available/awless.completion.bash
|
||||
completion/available/brew.completion.bash
|
||||
completion/available/cargo.completion.bash
|
||||
completion/available/composer.completion.bash
|
||||
completion/available/conda.completion.bash
|
||||
completion/available/consul.completion.bash
|
||||
completion/available/docker.completion.bash
|
||||
|
|
|
|||
|
|
@ -1,20 +1,14 @@
|
|||
#!/usr/bin/env bash
|
||||
# shellcheck shell=bash
|
||||
cite "about-completion"
|
||||
about-completion "composer completion"
|
||||
|
||||
_composer()
|
||||
{
|
||||
local cur script coms opts com
|
||||
function __composer_completion() {
|
||||
local cur coms opts com
|
||||
COMPREPLY=()
|
||||
_get_comp_words_by_ref -n : cur words
|
||||
|
||||
# for an alias, get the real script behind it
|
||||
if [[ $(type -t ${words[0]}) == "alias" ]]; then
|
||||
script=$(alias ${words[0]} | sed -E "s/alias ${words[0]}='(.*)'/\1/")
|
||||
else
|
||||
script=${words[0]}
|
||||
fi
|
||||
|
||||
# lookup for command
|
||||
for word in ${words[@]:1}; do
|
||||
for word in "${words[@]:1}"; do
|
||||
if [[ $word != -* ]]; then
|
||||
com=$word
|
||||
break
|
||||
|
|
@ -22,7 +16,7 @@ _composer()
|
|||
done
|
||||
|
||||
# completing for an option
|
||||
if [[ ${cur} == --* ]] ; then
|
||||
if [[ ${cur} == --* ]]; then
|
||||
opts="--help --quiet --verbose --version --ansi --no-ansi --no-interaction --profile --no-plugins --working-dir"
|
||||
|
||||
case "$com" in
|
||||
|
|
@ -113,21 +107,23 @@ _composer()
|
|||
|
||||
esac
|
||||
|
||||
COMPREPLY=($(compgen -W "${opts}" -- ${cur}))
|
||||
# shellcheck disable=SC2207
|
||||
COMPREPLY=($(compgen -W "${opts}" -- "${cur}"))
|
||||
__ltrim_colon_completions "$cur"
|
||||
|
||||
return 0;
|
||||
return 0
|
||||
fi
|
||||
|
||||
# completing for a command
|
||||
if [[ $cur == $com ]]; then
|
||||
if [[ "$cur" == "$com" ]]; then
|
||||
coms="about archive browse clear-cache config create-project depends diagnose dump-autoload exec global help init install licenses list outdated prohibits remove require run-script search self-update show status suggests update validate"
|
||||
|
||||
COMPREPLY=($(compgen -W "${coms}" -- ${cur}))
|
||||
# shellcheck disable=SC2207
|
||||
COMPREPLY=($(compgen -W "${coms}" -- "${cur}"))
|
||||
__ltrim_colon_completions "$cur"
|
||||
|
||||
return 0
|
||||
fi
|
||||
}
|
||||
|
||||
complete -o default -F _composer composer
|
||||
complete -o default -F __composer_completion composer
|
||||
|
|
|
|||
Loading…
Reference in New Issue