formatted composer completion and used helper function

pull/1807/head
Gurkirat Singh 2021-01-10 19:21:40 +05:30 committed by Noah Gorny
parent 1fbd91ebf9
commit dbfcb431a8
2 changed files with 121 additions and 119 deletions

View File

@ -62,6 +62,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

View File

@ -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
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/")
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 +23,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,17 +114,17 @@ _composer()
esac
COMPREPLY=($(compgen -W "${opts}" -- ${cur}))
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}))
COMPREPLY=($(compgen -W "${coms}" -- "${cur}"))
__ltrim_colon_completions "$cur"
return 0