Merge pull request #1807 from NoahGorny/cleanup/composer-completions

formatted composer completion and used helper function
pull/1835/head
Noah Gorny 2021-02-06 23:32:58 +02:00 committed by GitHub
commit 25c1c8978e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 118 additions and 121 deletions

View File

@ -63,6 +63,7 @@ plugins/available/xterm.plugin.bash
completion/available/awless.completion.bash completion/available/awless.completion.bash
completion/available/brew.completion.bash completion/available/brew.completion.bash
completion/available/cargo.completion.bash completion/available/cargo.completion.bash
completion/available/composer.completion.bash
completion/available/conda.completion.bash completion/available/conda.completion.bash
completion/available/consul.completion.bash completion/available/consul.completion.bash
completion/available/docker.completion.bash completion/available/docker.completion.bash

View File

@ -1,20 +1,14 @@
#!/usr/bin/env bash # shellcheck shell=bash
cite "about-completion"
about-completion "composer completion"
_composer() function __composer_completion() {
{ local cur coms opts com
local cur script coms opts com
COMPREPLY=() COMPREPLY=()
_get_comp_words_by_ref -n : cur words _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 # lookup for command
for word in ${words[@]:1}; do for word in "${words[@]:1}"; do
if [[ $word != -* ]]; then if [[ $word != -* ]]; then
com=$word com=$word
break break
@ -22,7 +16,7 @@ _composer()
done done
# completing for an option # 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" opts="--help --quiet --verbose --version --ansi --no-ansi --no-interaction --profile --no-plugins --working-dir"
case "$com" in case "$com" in
@ -113,21 +107,23 @@ _composer()
esac esac
COMPREPLY=($(compgen -W "${opts}" -- ${cur})) # shellcheck disable=SC2207
COMPREPLY=($(compgen -W "${opts}" -- "${cur}"))
__ltrim_colon_completions "$cur" __ltrim_colon_completions "$cur"
return 0; return 0
fi fi
# completing for a command # 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" 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" __ltrim_colon_completions "$cur"
return 0 return 0
fi fi
} }
complete -o default -F _composer composer complete -o default -F __composer_completion composer