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/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,133 +1,134 @@
#!/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
fi fi
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
about) about)
opts="${opts} " opts="${opts} "
;; ;;
archive) archive)
opts="${opts} --format --dir --file" opts="${opts} --format --dir --file"
;; ;;
browse) browse)
opts="${opts} --homepage --show" opts="${opts} --homepage --show"
;; ;;
clear-cache) clear-cache)
opts="${opts} " opts="${opts} "
;; ;;
config) config)
opts="${opts} --global --editor --auth --unset --list --file --absolute" opts="${opts} --global --editor --auth --unset --list --file --absolute"
;; ;;
create-project) create-project)
opts="${opts} --stability --prefer-source --prefer-dist --repository --repository-url --dev --no-dev --no-custom-installers --no-scripts --no-progress --no-secure-http --keep-vcs --no-install --ignore-platform-reqs" opts="${opts} --stability --prefer-source --prefer-dist --repository --repository-url --dev --no-dev --no-custom-installers --no-scripts --no-progress --no-secure-http --keep-vcs --no-install --ignore-platform-reqs"
;; ;;
depends) depends)
opts="${opts} --recursive --tree" opts="${opts} --recursive --tree"
;; ;;
diagnose) diagnose)
opts="${opts} " opts="${opts} "
;; ;;
dump-autoload) dump-autoload)
opts="${opts} --no-scripts --optimize --classmap-authoritative --apcu --no-dev" opts="${opts} --no-scripts --optimize --classmap-authoritative --apcu --no-dev"
;; ;;
exec) exec)
opts="${opts} --list" opts="${opts} --list"
;; ;;
global) global)
opts="${opts} " opts="${opts} "
;; ;;
help) help)
opts="${opts} --xml --format --raw" opts="${opts} --xml --format --raw"
;; ;;
init) init)
opts="${opts} --name --description --author --type --homepage --require --require-dev --stability --license --repository" opts="${opts} --name --description --author --type --homepage --require --require-dev --stability --license --repository"
;; ;;
install) install)
opts="${opts} --prefer-source --prefer-dist --dry-run --dev --no-dev --no-custom-installers --no-autoloader --no-scripts --no-progress --no-suggest --optimize-autoloader --classmap-authoritative --apcu-autoloader --ignore-platform-reqs" opts="${opts} --prefer-source --prefer-dist --dry-run --dev --no-dev --no-custom-installers --no-autoloader --no-scripts --no-progress --no-suggest --optimize-autoloader --classmap-authoritative --apcu-autoloader --ignore-platform-reqs"
;; ;;
licenses) licenses)
opts="${opts} --format --no-dev" opts="${opts} --format --no-dev"
;; ;;
list) list)
opts="${opts} --xml --raw --format" opts="${opts} --xml --raw --format"
;; ;;
outdated) outdated)
opts="${opts} --outdated --all --direct --strict" opts="${opts} --outdated --all --direct --strict"
;; ;;
prohibits) prohibits)
opts="${opts} --recursive --tree" opts="${opts} --recursive --tree"
;; ;;
remove) remove)
opts="${opts} --dev --no-progress --no-update --no-scripts --update-no-dev --update-with-dependencies --no-update-with-dependencies --ignore-platform-reqs --optimize-autoloader --classmap-authoritative --apcu-autoloader" opts="${opts} --dev --no-progress --no-update --no-scripts --update-no-dev --update-with-dependencies --no-update-with-dependencies --ignore-platform-reqs --optimize-autoloader --classmap-authoritative --apcu-autoloader"
;; ;;
require) require)
opts="${opts} --dev --prefer-source --prefer-dist --no-progress --no-suggest --no-update --no-scripts --update-no-dev --update-with-dependencies --ignore-platform-reqs --prefer-stable --prefer-lowest --sort-packages --optimize-autoloader --classmap-authoritative --apcu-autoloader" opts="${opts} --dev --prefer-source --prefer-dist --no-progress --no-suggest --no-update --no-scripts --update-no-dev --update-with-dependencies --ignore-platform-reqs --prefer-stable --prefer-lowest --sort-packages --optimize-autoloader --classmap-authoritative --apcu-autoloader"
;; ;;
run-script) run-script)
opts="${opts} --timeout --dev --no-dev --list" opts="${opts} --timeout --dev --no-dev --list"
;; ;;
search) search)
opts="${opts} --only-name --type" opts="${opts} --only-name --type"
;; ;;
self-update) self-update)
opts="${opts} --rollback --clean-backups --no-progress --update-keys --stable --preview --snapshot" opts="${opts} --rollback --clean-backups --no-progress --update-keys --stable --preview --snapshot"
;; ;;
show) show)
opts="${opts} --all --installed --platform --available --self --name-only --path --tree --latest --outdated --minor-only --direct --strict" opts="${opts} --all --installed --platform --available --self --name-only --path --tree --latest --outdated --minor-only --direct --strict"
;; ;;
status) status)
opts="${opts} " opts="${opts} "
;; ;;
suggests) suggests)
opts="${opts} --by-package --by-suggestion --no-dev" opts="${opts} --by-package --by-suggestion --no-dev"
;; ;;
update) update)
opts="${opts} --prefer-source --prefer-dist --dry-run --dev --no-dev --lock --no-custom-installers --no-autoloader --no-scripts --no-progress --no-suggest --with-dependencies --optimize-autoloader --classmap-authoritative --apcu-autoloader --ignore-platform-reqs --prefer-stable --prefer-lowest --interactive --root-reqs" opts="${opts} --prefer-source --prefer-dist --dry-run --dev --no-dev --lock --no-custom-installers --no-autoloader --no-scripts --no-progress --no-suggest --with-dependencies --optimize-autoloader --classmap-authoritative --apcu-autoloader --ignore-platform-reqs --prefer-stable --prefer-lowest --interactive --root-reqs"
;; ;;
validate) validate)
opts="${opts} --no-check-all --no-check-lock --no-check-publish --with-dependencies --strict" opts="${opts} --no-check-all --no-check-lock --no-check-publish --with-dependencies --strict"
;; ;;
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
fi fi
} }
complete -o default -F _composer composer complete -o default -F _composer composer