From dbfcb431a8db1f1f3cc2aa7d8e0fbbdfd634acca Mon Sep 17 00:00:00 2001 From: Gurkirat Singh Date: Sun, 10 Jan 2021 19:21:40 +0530 Subject: [PATCH 1/4] formatted composer completion and used helper function --- clean_files.txt | 1 + completion/available/composer.completion.bash | 239 +++++++++--------- 2 files changed, 121 insertions(+), 119 deletions(-) diff --git a/clean_files.txt b/clean_files.txt index 7e901805..5fe9be31 100644 --- a/clean_files.txt +++ b/clean_files.txt @@ -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 diff --git a/completion/available/composer.completion.bash b/completion/available/composer.completion.bash index be19fd27..b20da814 100644 --- a/completion/available/composer.completion.bash +++ b/completion/available/composer.completion.bash @@ -1,133 +1,134 @@ -#!/usr/bin/env bash +# shellcheck shell=bash +cite "about-completion" +about-completion "composer completion" -_composer() -{ - local cur script coms opts com - COMPREPLY=() - _get_comp_words_by_ref -n : cur words +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/") - else - script=${words[0]} - fi + # 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 - if [[ $word != -* ]]; then - com=$word - break - fi - done + # lookup for command + for word in "${words[@]:1}"; do + if [[ $word != -* ]]; then + com=$word + break + fi + done - # completing for an option - if [[ ${cur} == --* ]] ; then - opts="--help --quiet --verbose --version --ansi --no-ansi --no-interaction --profile --no-plugins --working-dir" + # completing for an option + if [[ ${cur} == --* ]]; then + opts="--help --quiet --verbose --version --ansi --no-ansi --no-interaction --profile --no-plugins --working-dir" - case "$com" in - about) - opts="${opts} " - ;; - archive) - opts="${opts} --format --dir --file" - ;; - browse) - opts="${opts} --homepage --show" - ;; - clear-cache) - opts="${opts} " - ;; - config) - opts="${opts} --global --editor --auth --unset --list --file --absolute" - ;; - 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" - ;; - depends) - opts="${opts} --recursive --tree" - ;; - diagnose) - opts="${opts} " - ;; - dump-autoload) - opts="${opts} --no-scripts --optimize --classmap-authoritative --apcu --no-dev" - ;; - exec) - opts="${opts} --list" - ;; - global) - opts="${opts} " - ;; - help) - opts="${opts} --xml --format --raw" - ;; - init) - opts="${opts} --name --description --author --type --homepage --require --require-dev --stability --license --repository" - ;; - 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" - ;; - licenses) - opts="${opts} --format --no-dev" - ;; - list) - opts="${opts} --xml --raw --format" - ;; - outdated) - opts="${opts} --outdated --all --direct --strict" - ;; - prohibits) - opts="${opts} --recursive --tree" - ;; - 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" - ;; - 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" - ;; - run-script) - opts="${opts} --timeout --dev --no-dev --list" - ;; - search) - opts="${opts} --only-name --type" - ;; - self-update) - opts="${opts} --rollback --clean-backups --no-progress --update-keys --stable --preview --snapshot" - ;; - show) - opts="${opts} --all --installed --platform --available --self --name-only --path --tree --latest --outdated --minor-only --direct --strict" - ;; - status) - opts="${opts} " - ;; - suggests) - opts="${opts} --by-package --by-suggestion --no-dev" - ;; - 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" - ;; - validate) - opts="${opts} --no-check-all --no-check-lock --no-check-publish --with-dependencies --strict" - ;; + case "$com" in + about) + opts="${opts} " + ;; + archive) + opts="${opts} --format --dir --file" + ;; + browse) + opts="${opts} --homepage --show" + ;; + clear-cache) + opts="${opts} " + ;; + config) + opts="${opts} --global --editor --auth --unset --list --file --absolute" + ;; + 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" + ;; + depends) + opts="${opts} --recursive --tree" + ;; + diagnose) + opts="${opts} " + ;; + dump-autoload) + opts="${opts} --no-scripts --optimize --classmap-authoritative --apcu --no-dev" + ;; + exec) + opts="${opts} --list" + ;; + global) + opts="${opts} " + ;; + help) + opts="${opts} --xml --format --raw" + ;; + init) + opts="${opts} --name --description --author --type --homepage --require --require-dev --stability --license --repository" + ;; + 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" + ;; + licenses) + opts="${opts} --format --no-dev" + ;; + list) + opts="${opts} --xml --raw --format" + ;; + outdated) + opts="${opts} --outdated --all --direct --strict" + ;; + prohibits) + opts="${opts} --recursive --tree" + ;; + 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" + ;; + 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" + ;; + run-script) + opts="${opts} --timeout --dev --no-dev --list" + ;; + search) + opts="${opts} --only-name --type" + ;; + self-update) + opts="${opts} --rollback --clean-backups --no-progress --update-keys --stable --preview --snapshot" + ;; + show) + opts="${opts} --all --installed --platform --available --self --name-only --path --tree --latest --outdated --minor-only --direct --strict" + ;; + status) + opts="${opts} " + ;; + suggests) + opts="${opts} --by-package --by-suggestion --no-dev" + ;; + 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" + ;; + validate) + opts="${opts} --no-check-all --no-check-lock --no-check-publish --with-dependencies --strict" + ;; - esac + esac - COMPREPLY=($(compgen -W "${opts}" -- ${cur})) - __ltrim_colon_completions "$cur" + COMPREPLY=($(compgen -W "${opts}" -- "${cur}")) + __ltrim_colon_completions "$cur" - return 0; - fi + return 0 + fi - # completing for a command - 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" + # completing for a command + 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})) - __ltrim_colon_completions "$cur" + COMPREPLY=($(compgen -W "${coms}" -- "${cur}")) + __ltrim_colon_completions "$cur" - return 0 - fi + return 0 + fi } complete -o default -F _composer composer From e9f28ff7456d4f06efbac6299d2b106100f549a5 Mon Sep 17 00:00:00 2001 From: Noah Gorny Date: Fri, 22 Jan 2021 23:48:24 +0200 Subject: [PATCH 2/4] completion: composer: Add shellcheck directives --- completion/available/composer.completion.bash | 2 ++ 1 file changed, 2 insertions(+) diff --git a/completion/available/composer.completion.bash b/completion/available/composer.completion.bash index b20da814..7f802b79 100644 --- a/completion/available/composer.completion.bash +++ b/completion/available/composer.completion.bash @@ -114,6 +114,7 @@ function _composer() { esac + # shellcheck disable=SC2207 COMPREPLY=($(compgen -W "${opts}" -- "${cur}")) __ltrim_colon_completions "$cur" @@ -124,6 +125,7 @@ function _composer() { 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" + # shellcheck disable=SC2207 COMPREPLY=($(compgen -W "${coms}" -- "${cur}")) __ltrim_colon_completions "$cur" From 0d963b224f1332d9155d7865eeb530cc0d2111d0 Mon Sep 17 00:00:00 2001 From: Noah Gorny Date: Sat, 6 Feb 2021 00:19:05 +0200 Subject: [PATCH 3/4] completion: composer: Remove uneeded local "scripts" var --- completion/available/composer.completion.bash | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/completion/available/composer.completion.bash b/completion/available/composer.completion.bash index 7f802b79..4ed15546 100644 --- a/completion/available/composer.completion.bash +++ b/completion/available/composer.completion.bash @@ -3,17 +3,10 @@ cite "about-completion" about-completion "composer completion" function _composer() { - local cur script coms opts com + 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 if [[ $word != -* ]]; then From e4f600679716bc836163e8d50222d70814485ae6 Mon Sep 17 00:00:00 2001 From: Noah Gorny Date: Sat, 6 Feb 2021 20:37:28 +0200 Subject: [PATCH 4/4] completion: composer: Rename _composer->__composer_completion --- completion/available/composer.completion.bash | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/completion/available/composer.completion.bash b/completion/available/composer.completion.bash index 4ed15546..eefe50fa 100644 --- a/completion/available/composer.completion.bash +++ b/completion/available/composer.completion.bash @@ -2,7 +2,7 @@ cite "about-completion" about-completion "composer completion" -function _composer() { +function __composer_completion() { local cur coms opts com COMPREPLY=() _get_comp_words_by_ref -n : cur words @@ -126,4 +126,4 @@ function _composer() { fi } -complete -o default -F _composer composer +complete -o default -F __composer_completion composer