formatted composer completion and used helper function
parent
1fbd91ebf9
commit
dbfcb431a8
|
|
@ -62,6 +62,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
|
||||||
|
|
|
||||||
|
|
@ -1,20 +1,21 @@
|
||||||
#!/usr/bin/env bash
|
# shellcheck shell=bash
|
||||||
|
cite "about-completion"
|
||||||
|
about-completion "composer completion"
|
||||||
|
|
||||||
_composer()
|
function _composer() {
|
||||||
{
|
|
||||||
local cur script 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
|
# for an alias, get the real script behind it
|
||||||
if [[ $(type -t ${words[0]}) == "alias" ]]; then
|
if [[ $(type -t "${words[0]}") == "alias" ]]; then
|
||||||
script=$(alias ${words[0]} | sed -E "s/alias ${words[0]}='(.*)'/\1/")
|
script=$(alias "${words[0]}" | sed -E "s/alias ${words[0]}='(.*)'/\1/")
|
||||||
else
|
else
|
||||||
script=${words[0]}
|
script=${words[0]}
|
||||||
fi
|
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 +23,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,17 +114,17 @@ _composer()
|
||||||
|
|
||||||
esac
|
esac
|
||||||
|
|
||||||
COMPREPLY=($(compgen -W "${opts}" -- ${cur}))
|
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}))
|
COMPREPLY=($(compgen -W "${coms}" -- "${cur}"))
|
||||||
__ltrim_colon_completions "$cur"
|
__ltrim_colon_completions "$cur"
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue