diff --git a/clean_files.txt b/clean_files.txt index 54180c19fd..6273bccc7b 100644 --- a/clean_files.txt +++ b/clean_files.txt @@ -33,50 +33,80 @@ lint_clean_files.sh # completion/available/apm.completion.bash completion/available/awless.completion.bash +completion/available/awscli.completion.bash completion/available/bash-it.completion.bash completion/available/brew.completion.bash +#completion/available/capistrano.completion.bash completion/available/cargo.completion.bash completion/available/composer.completion.bash completion/available/conda.completion.bash completion/available/consul.completion.bash +completion/available/crystal.completion.bash completion/available/dart.completion.bash +completion/available/defaults.completion.bash +completion/available/dirs.completion.bash completion/available/django.completion.bash completion/available/dmidecode.completion.bash completion/available/docker-machine.completion.bash completion/available/docker.completion.bash completion/available/dotnet.completion.bash +completion/available/drush.completion.bash +completion/available/export.completion.bash +completion/available/flutter.completion.bash completion/available/gcloud.completion.bash completion/available/gem.completion.bash completion/available/git.completion.bash completion/available/github-cli.completion.bash completion/available/go.completion.bash completion/available/helm.completion.bash +completion/available/homesick.completion.bash completion/available/jboss5.completion.bash completion/available/jboss7.completion.bash completion/available/jungle.completion.bash +completion/available/kind.completion.bash completion/available/knife.completion.bash completion/available/kontena.completion.bash completion/available/kubectl.completion.bash completion/available/laravel.completion.bash completion/available/lerna.completion.bash +completion/available/makefile.completion.bash +#completion/available/maven.completion.bash completion/available/minikube.completion.bash +completion/available/minishift.completion.bash +completion/available/ng.completion.bash completion/available/ngrok.completion.bash completion/available/notify-send.completion.bash completion/available/npm.completion.bash +completion/available/nvm.completion.bash +completion/available/openshift.completion.bash completion/available/packer.completion.bash +completion/available/pew.completion.bash completion/available/pip.completion.bash completion/available/pip3.completion.bash completion/available/pipenv.completion.bash completion/available/pipx.completion.bash +#completion/available/projects.completion.bash +#completion/available/rake.completion.bash completion/available/rustup.completion.bash +completion/available/rvm.completion.bash completion/available/sdkman.completion.bash +#completion/available/sqlmap.completion.bash +#completion/available/ssh.completion.bash +completion/available/svn.completion.bash completion/available/system.completion.bash +completion/available/terraform.completion.bash +#completion/available/test_kitchen.completion.bash +completion/available/todo.completion.bash +completion/available/travis.completion.bash completion/available/vault.completion.bash +completion/available/virsh.completion.bash +#completion/available/virtualbox.completion.bash completion/available/vuejs.completion.bash completion/available/wpscan.completion.bash # libraries lib/colors.bash +lib/completion.bash lib/helpers.bash lib/history.bash lib/log.bash diff --git a/completion/available/apm.completion.bash b/completion/available/apm.completion.bash index c3dcfe45f8..9737938f24 100644 --- a/completion/available/apm.completion.bash +++ b/completion/available/apm.completion.bash @@ -1,4 +1,4 @@ # shellcheck shell=bash about-completion "apm completion" -# shellcheck disable=SC1090 -source "${BASH_IT}"/vendor/github.com/vigo/apm-bash-completion/apm +# shellcheck source-path=SCRIPTDIR/../../vendor/github.com/vigo/apm-bash-completion +source "${BASH_IT?}/vendor/github.com/vigo/apm-bash-completion/apm" diff --git a/completion/available/awless.completion.bash b/completion/available/awless.completion.bash index 98a5d38881..9d175e7502 100644 --- a/completion/available/awless.completion.bash +++ b/completion/available/awless.completion.bash @@ -1,5 +1,10 @@ # shellcheck shell=bash -if _command_exists awless; then - # shellcheck disable=SC1090 - source <(awless completion bash) -fi + +# Make sure awless is installed +_bash-it-completion-helper-necessary awless || return + +# Don't handle completion if it's already managed +_bash-it-completion-helper-sufficient awless || return + +# shellcheck disable=SC1090 +source <(awless completion bash) diff --git a/completion/available/awscli.completion.bash b/completion/available/awscli.completion.bash index a30418373a..bb5bd6b0d5 100644 --- a/completion/available/awscli.completion.bash +++ b/completion/available/awscli.completion.bash @@ -1,6 +1,9 @@ # shellcheck shell=bash -if _command_exists aws_completer -then - complete -C "$(command -v aws_completer)" aws -fi +# Make sure aws is installed +_bash-it-completion-helper-necessary aws aws_completer || return + +# Don't handle completion if it's already managed +_bash-it-completion-helper-sufficient aws || return + +complete -C aws_completer aws diff --git a/completion/available/cargo.completion.bash b/completion/available/cargo.completion.bash index d276ee7298..d40d4d4948 100644 --- a/completion/available/cargo.completion.bash +++ b/completion/available/cargo.completion.bash @@ -1,6 +1,10 @@ # shellcheck shell=bash -# cargo (Rust package manager) completion +about-completion "cargo (Rust package manager) completion" -if _binary_exists rustup && _binary_exists cargo; then - eval "$(rustup completions bash cargo)" -fi +# Make sure cargo is installed +_bash-it-completion-helper-necessary rustup cargo || return + +# Don't handle completion if it's already managed +_bash-it-completion-helper-sufficient cargo || return + +eval "$(rustup completions bash cargo)" diff --git a/completion/available/conda.completion.bash b/completion/available/conda.completion.bash index f5a61e5907..84399caec3 100644 --- a/completion/available/conda.completion.bash +++ b/completion/available/conda.completion.bash @@ -1,5 +1,4 @@ # shellcheck shell=bash -cite "about-completion" about-completion "conda completion" if _command_exists conda; then diff --git a/completion/available/consul.completion.bash b/completion/available/consul.completion.bash index 511cf37209..2fbc6c6941 100644 --- a/completion/available/consul.completion.bash +++ b/completion/available/consul.completion.bash @@ -1,7 +1,10 @@ # shellcheck shell=bash -cite "about-completion" about-completion "Hashicorp consul completion" -if _command_exists consul; then - complete -C "$(command -v consul)" consul -fi +# Make sure consul is installed +_bash-it-completion-helper-necessary consul || return + +# Don't handle completion if it's already managed +_bash-it-completion-helper-sufficient consul || return + +complete -C consul consul diff --git a/completion/available/crystal.completion.bash b/completion/available/crystal.completion.bash index 7644ffd4d4..950459aa71 100644 --- a/completion/available/crystal.completion.bash +++ b/completion/available/crystal.completion.bash @@ -1 +1,4 @@ -_log_warning 'Bash completion for "crystal" is now covered by "system". This completion can be disabled.' +# shellcheck shell=bash + +_log_warning 'Bash completion for "crystal" is now covered by "system".' +_disable-completion "crystal" diff --git a/completion/available/defaults.completion.bash b/completion/available/defaults.completion.bash index 39d7ea95b0..9fb00da619 100644 --- a/completion/available/defaults.completion.bash +++ b/completion/available/defaults.completion.bash @@ -1,5 +1,6 @@ # shellcheck shell=bash -if test -s "${BASH_IT?}/vendor/github.com/gaelicWizard/bash-progcomp/defaults.completion.bash"; then - source "$_" +if [[ -s "${BASH_IT?}/vendor/github.com/gaelicWizard/bash-progcomp/defaults.completion.bash" ]]; then + # shellcheck source-path=SCRIPTDIR/../../vendor/github.com/gaelicWizard/bash-progcomp + source "${BASH_IT?}/vendor/github.com/gaelicWizard/bash-progcomp/defaults.completion.bash" fi diff --git a/completion/available/dirs.completion.bash b/completion/available/dirs.completion.bash index ba18db3241..187de36119 100644 --- a/completion/available/dirs.completion.bash +++ b/completion/available/dirs.completion.bash @@ -1,15 +1,13 @@ -#!/usr/bin/env bash -# Bash completion support for the 'dirs' plugin (commands G, R). +# shellcheck shell=bash +about-completion "Bash completion support for the 'dirs' plugin (commands G, R)." -_dirs-complete() { - local CURRENT_PROMPT="${COMP_WORDS[COMP_CWORD]}" +function _dirs-complete() { + # parse all defined shortcuts ${BASH_IT_DIRS_BKS} + if [[ -s "${BASH_IT_DIRS_BKS:-/dev/null}" ]]; then + IFS=$'\n' read -d '' -ra COMPREPLY < <(grep -v '^#' "${BASH_IT_DIRS_BKS?}" | sed -e 's/\(.*\)=.*/\1/') + fi - # parse all defined shortcuts from ~/.dirs - if [ -r "$HOME/.dirs" ]; then - COMPREPLY=($(compgen -W "$(grep -v '^#' ~/.dirs | sed -e 's/\(.*\)=.*/\1/')" -- ${CURRENT_PROMPT}) ) - fi - - return 0 + return 0 } -complete -o default -o nospace -F _dirs-complete G R +complete -o default -o nospace -F _dirs-complete -X '!&*' G R diff --git a/completion/available/dmidecode.completion.bash b/completion/available/dmidecode.completion.bash index 4a8845244e..eacfee81fe 100644 --- a/completion/available/dmidecode.completion.bash +++ b/completion/available/dmidecode.completion.bash @@ -1,22 +1,25 @@ # shellcheck shell=bash -function __dmidecode_completion() { - # shellcheck disable=SC2155 - local prev=$(_get_pword) - # shellcheck disable=SC2155 - local curr=$(_get_cword) +# Make sure dmidecode is installed +_bash-it-completion-helper-necessary dmidecode || : + +# Don't handle completion if it's already managed +_bash-it-completion-helper-sufficient dmidecode || return + +function _dmidecode() { + local prev="${COMP_WORDS[COMP_CWORD - 1]}" case $prev in -s | --string | -t | --type) OPTS=$(dmidecode "$prev" 2>&1 | grep -E '^ ' | sed 's/ *//g') # shellcheck disable=SC2207 - COMPREPLY=($(compgen -W "$OPTS" -- "$curr")) + COMPREPLY=("${OPTS[@]}") ;; dmidecode) # shellcheck disable=SC2207 - COMPREPLY=($(compgen -W "-d --dev-mem -h --help -q --quiet -s --string -t --type -H --handle -u --dump{,-bin} --from-dump --no-sysfs --oem-string -V --version" -- "$curr")) + COMPREPLY=("-d" "--dev-mem" "-h" "--help" "-q" "--quiet" "-s" "--string" "-t" "--type" "-H" "--handle" "-u" "--dump" "-dump-bin" "--from-dump" "--no-sysfs" "--oem-string" "-V" "--version") ;; esac } -complete -F __dmidecode_completion dmidecode +complete -F _dmidecode -X '!&*' dmidecode diff --git a/completion/available/docker.completion.bash b/completion/available/docker.completion.bash index 3f83a87461..b23be80e4b 100644 --- a/completion/available/docker.completion.bash +++ b/completion/available/docker.completion.bash @@ -1,24 +1,32 @@ # shellcheck shell=bash -cite "about-completion" about-completion "docker completion" # Make sure docker is installed -_command_exists docker || return +_bash-it-completion-helper-necessary docker || : # Don't handle completion if it's already managed -_completion_exists docker && return +_bash-it-completion-helper-sufficient docker || return _docker_bash_completion_paths=( - # MacOS + # MacOS App '/Applications/Docker.app/Contents/Resources/etc/docker.bash-completion' - # Linux + # Command Line '/usr/share/bash-completion/completions/docker' ) -for fn in "${_docker_bash_completion_paths[@]}"; do - if [ -r "$fn" ]; then +# Load the first completion file found +_docker_bash_completion_found=false +for _comp_path in "${_docker_bash_completion_paths[@]}"; do + if [[ -r "$_comp_path" ]]; then + _docker_bash_completion_found=true # shellcheck disable=SC1090 - source "$fn" + source "$_comp_path" break fi done + +# Cleanup +if [[ "${_docker_bash_completion_found}" == false ]]; then + _log_warning "no completion files found - please try enabling the 'system' completion instead." +fi +unset "${!_docker_bash_completion@}" diff --git a/completion/available/drush.completion.bash b/completion/available/drush.completion.bash index 6628c65513..3bc81f1905 100644 --- a/completion/available/drush.completion.bash +++ b/completion/available/drush.completion.bash @@ -1,2 +1,5 @@ +# shellcheck shell=bash + _log_warning 'Bash completion for "drush" is now deprecated, as it used code with incompatible license. Please disable this completion and use the instructions from "drush" developers instead.' +_disable-completion "drush" diff --git a/completion/available/export.completion.bash b/completion/available/export.completion.bash index 42da3a97be..361ead75b6 100644 --- a/completion/available/export.completion.bash +++ b/completion/available/export.completion.bash @@ -1 +1,4 @@ -complete -o nospace -S = -W '$(printenv | awk -F= "{print \$1}")' export +# shellcheck shell=bash + +_log_warning 'Bash completion for "export" is now covered by "system".' +_disable-completion "export" diff --git a/completion/available/flutter.completion.bash b/completion/available/flutter.completion.bash index 62befc824d..cc965b579e 100644 --- a/completion/available/flutter.completion.bash +++ b/completion/available/flutter.completion.bash @@ -1,5 +1,9 @@ -#!/usr/bin/bash +# shellcheck shell=bash -if _command_exists flutter; then - eval "$(flutter bash-completion)" -fi +# Make sure flutter is installed +_bash-it-completion-helper-necessary flutter || return + +# Don't handle completion if it's already managed +_bash-it-completion-helper-sufficient flutter || return + +eval "$(flutter bash-completion)" diff --git a/completion/available/gcloud.completion.bash b/completion/available/gcloud.completion.bash index 63073e8ed3..514d8b4c3d 100644 --- a/completion/available/gcloud.completion.bash +++ b/completion/available/gcloud.completion.bash @@ -1,5 +1,4 @@ # shellcheck shell=bash -cite "about-completion" about-completion "Google Cloud SDK completion" if _command_exists gcloud; then diff --git a/completion/available/git.completion.bash b/completion/available/git.completion.bash index 31b77fa3de..d9fe014c91 100644 --- a/completion/available/git.completion.bash +++ b/completion/available/git.completion.bash @@ -3,13 +3,10 @@ # Locate and load completions for `git`. # Make sure git is installed -_command_exists git || return +_bash-it-completion-helper-necessary git || : # Don't handle completion if it's already managed -if complete -p git &> /dev/null; then - _log_warning "completion already loaded - this usually means it is safe to stop using this completion" - return 0 -fi +_bash-it-completion-helper-sufficient git || return _git_bash_completion_xcrun_git= if _command_exists xcrun; then diff --git a/completion/available/github-cli.completion.bash b/completion/available/github-cli.completion.bash index 4a6113945c..0888c6c5eb 100644 --- a/completion/available/github-cli.completion.bash +++ b/completion/available/github-cli.completion.bash @@ -1,9 +1,10 @@ # shellcheck shell=bash -cite "about-completion" about-completion "GitHub CLI completion" -if _binary_exists gh; then - # If gh already completed, stop - _completion_exists gh && return - eval "$(gh completion --shell=bash)" -fi +# Make sure gh is installed +_bash-it-completion-helper-necessary gh || return + +# Don't handle completion if it's already managed +_bash-it-completion-helper-sufficient gh || return + +eval "$(gh completion --shell=bash)" diff --git a/completion/available/helm.completion.bash b/completion/available/helm.completion.bash index 0dae7af46b..d11b4c305b 100644 --- a/completion/available/helm.completion.bash +++ b/completion/available/helm.completion.bash @@ -1,7 +1,10 @@ # shellcheck shell=bash -cite "about-completion" about-completion "helm (Kubernetes Package Manager) completion" -if _command_exists helm; then - eval "$(helm completion bash)" -fi +# Make sure helm is installed +_bash-it-completion-helper-necessary helm || return + +# Don't handle completion if it's already managed +_bash-it-completion-helper-sufficient helm || return + +eval "$(helm completion bash)" diff --git a/completion/available/homesick.completion.bash b/completion/available/homesick.completion.bash index ed6f6e79ed..cd2e00b0a8 100644 --- a/completion/available/homesick.completion.bash +++ b/completion/available/homesick.completion.bash @@ -1,2 +1,5 @@ +# shellcheck shell=bash + _log_warning 'Bash completion for "homesick" is now deprecated, as it used unlicensed code. Please disable this completion and use the instructions from "homesick" bash completion developers instead.' +_disable-completion "homesick" diff --git a/completion/available/jungle.completion.bash b/completion/available/jungle.completion.bash index e190d1438a..60aa398920 100644 --- a/completion/available/jungle.completion.bash +++ b/completion/available/jungle.completion.bash @@ -1,7 +1,10 @@ # shellcheck shell=bash -cite "about-completion" about-completion "jungle(AWS cli tool) completion" -if _command_exists jungle; then - eval "$(_JUNGLE_COMPLETE=source jungle)" -fi +# Make sure jungle is installed +_bash-it-completion-helper-necessary jungle || return + +# Don't handle completion if it's already managed +_bash-it-completion-helper-sufficient jungle || return + +eval "$(_JUNGLE_COMPLETE=source jungle)" diff --git a/completion/available/kind.completion.bash b/completion/available/kind.completion.bash index be12a2d29c..8530dcd454 100644 --- a/completion/available/kind.completion.bash +++ b/completion/available/kind.completion.bash @@ -1,5 +1,9 @@ -#!/usr/bin/env bash +# shellcheck shell=bash -if _command_exists kind; then - eval "$(kind completion bash)" -fi +# Make sure kind is installed +_bash-it-completion-helper-necessary kind || return + +# Don't handle completion if it's already managed +_bash-it-completion-helper-sufficient kind || return + +eval "$(kind completion bash)" diff --git a/completion/available/kontena.completion.bash b/completion/available/kontena.completion.bash index 916ee15f92..08f6ef634b 100644 --- a/completion/available/kontena.completion.bash +++ b/completion/available/kontena.completion.bash @@ -1,5 +1,10 @@ # shellcheck shell=bash -if _command_exists kontena; then - # shellcheck disable=SC1090 - source "$(kontena whoami --bash-completion-path)" -fi + +# Make sure kontena is installed +_bash-it-completion-helper-necessary kontena || return + +# Don't handle completion if it's already managed +_bash-it-completion-helper-sufficient kontena || return + +# shellcheck disable=SC1090 +source "$(kontena whoami --bash-completion-path)" diff --git a/completion/available/kubectl.completion.bash b/completion/available/kubectl.completion.bash index a9c498b601..f3d9ec5a94 100644 --- a/completion/available/kubectl.completion.bash +++ b/completion/available/kubectl.completion.bash @@ -1,7 +1,10 @@ # shellcheck shell=bash -cite "about-completion" about-completion "kubectl (Kubernetes CLI) completion" -if _binary_exists kubectl; then - eval "$(kubectl completion bash)" -fi +# Make sure kubectl is installed +_bash-it-completion-helper-necessary kubectl || return + +# Don't handle completion if it's already managed +_bash-it-completion-helper-sufficient kubectl || return + +eval "$(kubectl completion bash)" diff --git a/completion/available/laravel.completion.bash b/completion/available/laravel.completion.bash index 8f03256896..63693fe257 100644 --- a/completion/available/laravel.completion.bash +++ b/completion/available/laravel.completion.bash @@ -1,6 +1,10 @@ # shellcheck shell=bash -_command_exists laravel || return +# Make sure laravel is installed +_bash-it-completion-helper-necessary laravel || : + +# Don't handle completion if it's already managed +_bash-it-completion-helper-sufficient laravel || return function __laravel_completion() { local OPTS=('-h' '--help' '-q' '--quiet' '--ansi' '--no-ansi' '-n' '--no-interaction' '-v' '-vv' '-vvv' '--verbose' 'help' 'list' 'new') diff --git a/completion/available/makefile.completion.bash b/completion/available/makefile.completion.bash index e72ba6fd3b..b518bb5793 100644 --- a/completion/available/makefile.completion.bash +++ b/completion/available/makefile.completion.bash @@ -1,33 +1,35 @@ +# shellcheck shell=bash + # Bash completion for Makefile # Loosely adapted from http://stackoverflow.com/a/38415982/1472048 -_makecomplete() { - COMPREPLY=() +function _makecomplete() { + local cur="${COMP_WORDS[COMP_CWORD]}" + local files=() targets=() line f + COMPREPLY=() - # https://www.gnu.org/software/make/manual/html_node/Makefile-Names.html - local files=() - for f in 'GNUmakefile' 'makefile' 'Makefile' ; do - [ -f "$f" ] && files+=("$f") - done + # https://www.gnu.org/software/make/manual/html_node/Makefile-Names.html + for f in 'GNUmakefile' 'makefile' 'Makefile'; do + [[ -f "$f" ]] && files+=("$f") + done - [ "${#files[@]}" -eq 0 ] && return 0 + [[ "${#files[@]}" -eq 0 ]] && return 0 - # collect all targets - local targets=() - for f in "${files[@]}" ; do - while IFS='' read -r line ; do - targets+=("$line") - done < <(grep -oE '^[a-zA-Z0-9_-]+:([^=]|$)' "$f" | cut -d':' -f1) - done + # collect all targets + for f in "${files[@]}"; do + while IFS='' read -r line; do + targets+=("$line") + done < <(grep -oE '^[a-zA-Z0-9_-]+:([^=]|$)' "$f" | cut -d':' -f1) + done - [ "${#targets[@]}" -eq 0 ] && return 0 + [[ "${#targets[@]}" -eq 0 ]] && return 0 - # use the targets for completion - while IFS='' read -r line ; do - COMPREPLY+=("$line") - done < <(compgen -W "$(tr ' ' '\n' <<<"${targets[@]}" | sort -u)" -- "${COMP_WORDS[COMP_CWORD]}") + # use the targets for completion + while IFS='' read -r line; do + COMPREPLY+=("$line") + done < <(compgen -W "$(tr ' ' '\n' <<< "${targets[@]}" | sort -u)" -- "${cur}") - return 0 + return 0 } complete -o nospace -F _makecomplete make diff --git a/completion/available/minikube.completion.bash b/completion/available/minikube.completion.bash index 44076362ce..c73a4da44f 100644 --- a/completion/available/minikube.completion.bash +++ b/completion/available/minikube.completion.bash @@ -1,6 +1,10 @@ # shellcheck shell=bash -# minikube (Local Kubernetes) completion +about-completion "minikube (Local Kubernetes) completion" -if _command_exists minikube; then - eval "$(minikube completion bash)" -fi +# Make sure minikube is installed +_bash-it-completion-helper-necessary minikube || return + +# Don't handle completion if it's already managed +_bash-it-completion-helper-sufficient minikube || return + +eval "$(minikube completion bash)" diff --git a/completion/available/minishift.completion.bash b/completion/available/minishift.completion.bash index 5679eae80f..dc872bc1bd 100644 --- a/completion/available/minishift.completion.bash +++ b/completion/available/minishift.completion.bash @@ -1 +1,10 @@ -_command_exists minishift && source <(minishift completion bash) +# shellcheck shell=bash + +# Make sure minishift is installed +_bash-it-completion-helper-necessary minishift || return + +# Don't handle completion if it's already managed +_bash-it-completion-helper-sufficient minishift || return + +# shellcheck disable=SC1090 +source <(minishift completion bash) diff --git a/completion/available/ng.completion.bash b/completion/available/ng.completion.bash index f219b30396..cba49c3b31 100644 --- a/completion/available/ng.completion.bash +++ b/completion/available/ng.completion.bash @@ -1,8 +1,15 @@ -if _command_exists ng; then - # No longer supported, please see https://github.com/angular/angular-cli/issues/11043 - # Fix courtesy of https://stackoverflow.com/questions/50194674/ng-completion-no-longer-exists - # . <(ng completion --bash) - - NG_COMMANDS="add build config doc e2e generate help lint new run serve test update version xi18n" - complete -W "$NG_COMMANDS" ng -fi +# shellcheck shell=bash + +# Make sure ng is installed +_bash-it-completion-helper-necessary ng || : + +# Don't handle completion if it's already managed +_bash-it-completion-helper-sufficient ng || return + +# No longer supported, please see https://github.com/angular/angular-cli/issues/11043 +# Fix courtesy of https://stackoverflow.com/questions/50194674/ng-completion-no-longer-exists +# source <(ng completion --bash) + +_ng_bash_completion_candidates=("add" "build" "config" "doc" "e2e" "generate" "help" "lint" "new" "run" "serve" "test" "update" "version" "xi18n") +complete -W "${_ng_bash_completion_candidates[*]}" ng +unset "${!_ng_bash_completion@}" diff --git a/completion/available/notify-send.completion.bash b/completion/available/notify-send.completion.bash index 676485f83a..4745b2abee 100644 --- a/completion/available/notify-send.completion.bash +++ b/completion/available/notify-send.completion.bash @@ -1,21 +1,22 @@ # shellcheck shell=bash -function __notify-send_completions() { - # shellcheck disable=SC2155 - local curr=$(_get_cword) - # shellcheck disable=SC2155 - local prev=$(_get_pword) +# Make sure notify-send is installed +_bash-it-completion-helper-necessary notify-send || : + +# Don't handle completion if it's already managed +_bash-it-completion-helper-sufficient notify-send || return + +function _notify-send() { + local prev="${COMP_WORDS[COMP_CWORD - 1]}" case $prev in -u | --urgency) - # shellcheck disable=SC2207 - COMPREPLY=($(compgen -W "low normal critical" -- "$curr")) + COMPREPLY=("low" "normal" "critical") ;; *) - # shellcheck disable=SC2207 - COMPREPLY=($(compgen -W "-? --help -u --urgency -t --expire-time -a --app-name -i --icon -c --category -h --hint -v --version" -- "$curr")) + COMPREPLY=("-?" "--help" "-u" "--urgency" "-t" "--expire-time" "-a" "--app-name" "-i" "--icon" "-c" "--category" "-h" "--hint" "-v" "--version") ;; esac } -complete -F __notify-send_completions notify-send +complete -F _notify-send -X '!&*' notify-send diff --git a/completion/available/npm.completion.bash b/completion/available/npm.completion.bash index cf24585ef7..3ceb620252 100644 --- a/completion/available/npm.completion.bash +++ b/completion/available/npm.completion.bash @@ -1,7 +1,10 @@ # shellcheck shell=bash -cite "about-completion" about-completion "npm (Node Package Manager) completion" -if _command_exists npm; then - eval "$(npm completion)" -fi +# Make sure npm is installed +_bash-it-completion-helper-necessary npm || return + +# Don't handle completion if it's already managed +_bash-it-completion-helper-sufficient npm || return + +eval "$(npm completion)" diff --git a/completion/available/nvm.completion.bash b/completion/available/nvm.completion.bash index a82b82b61a..9126f4d68b 100644 --- a/completion/available/nvm.completion.bash +++ b/completion/available/nvm.completion.bash @@ -1,8 +1,7 @@ -#!/usr/bin/env bash +# shellcheck shell=bash +about-completion "nvm (Node Version Manager) completion" -# nvm (Node Version Manager) completion - -if [ "$NVM_DIR" ] && [ -r "$NVM_DIR"/bash_completion ]; -then - . "$NVM_DIR"/bash_completion +if [[ -n "${NVM_DIR:-}" && -s "${NVM_DIR}/bash_completion" ]]; then + # shellcheck disable=SC1091 + source "${NVM_DIR}/bash_completion" fi diff --git a/completion/available/openshift.completion.bash b/completion/available/openshift.completion.bash index 1e7b681506..5d0e2dcdc3 100644 --- a/completion/available/openshift.completion.bash +++ b/completion/available/openshift.completion.bash @@ -1 +1,10 @@ -_command_exists oc && source <(oc completion bash) +# shellcheck shell=bash + +# Make sure oc is installed +_bash-it-completion-helper-necessary oc || return + +# Don't handle completion if it's already managed +_bash-it-completion-helper-sufficient oc || return + +# shellcheck disable=SC1090 +source <(oc completion bash) diff --git a/completion/available/packer.completion.bash b/completion/available/packer.completion.bash index 2301f0f226..049e17ae34 100644 --- a/completion/available/packer.completion.bash +++ b/completion/available/packer.completion.bash @@ -1,7 +1,10 @@ # shellcheck shell=bash -cite "about-completion" about-completion "packer completion" -if _binary_exists packer; then - complete -C packer packer -fi +# Make sure packer is installed +_bash-it-completion-helper-necessary packer || return + +# Don't handle completion if it's already managed +_bash-it-completion-helper-sufficient packer || return + +complete -C packer packer diff --git a/completion/available/pew.completion.bash b/completion/available/pew.completion.bash index 04e67ecbf5..221df24958 100644 --- a/completion/available/pew.completion.bash +++ b/completion/available/pew.completion.bash @@ -1,6 +1,10 @@ # shellcheck shell=bash -if _command_exists pew -then - source "$(pew shell_config)" -fi +# Make sure pew is installed +_bash-it-completion-helper-necessary pew || return + +# Don't handle completion if it's already managed +_bash-it-completion-helper-sufficient pew || return + +# shellcheck disable=SC1090 +source "$(pew shell_config)" diff --git a/completion/available/pipenv.completion.bash b/completion/available/pipenv.completion.bash index 4adfab9595..43cbe74e17 100644 --- a/completion/available/pipenv.completion.bash +++ b/completion/available/pipenv.completion.bash @@ -1,4 +1,9 @@ # shellcheck shell=bash -if _command_exists pipenv; then - eval "$(_PIPENV_COMPLETE=bash_source pipenv)" -fi + +# Make sure pipenv is installed +_bash-it-completion-helper-necessary pipenv || return + +# Don't handle completion if it's already managed +_bash-it-completion-helper-sufficient pipenv || return + +eval "$(_PIPENV_COMPLETE=bash_source pipenv)" diff --git a/completion/available/rustup.completion.bash b/completion/available/rustup.completion.bash index 1cf8bc95b4..1f1a38af2f 100644 --- a/completion/available/rustup.completion.bash +++ b/completion/available/rustup.completion.bash @@ -1,7 +1,10 @@ # shellcheck shell=bash +about-completion "rustup (Rust toolchain installer) completion" -# rustup (Rust toolchain installer) completion +# Make sure rustup is installed +_bash-it-completion-helper-necessary rustup || return -if _binary_exists rustup; then - eval "$(rustup completions bash)" -fi +# Don't handle completion if it's already managed +_bash-it-completion-helper-sufficient rustup || return + +eval "$(rustup completions bash)" diff --git a/completion/available/rvm.completion.bash b/completion/available/rvm.completion.bash index cd8ded0468..9bea6ebb67 100644 --- a/completion/available/rvm.completion.bash +++ b/completion/available/rvm.completion.bash @@ -1,5 +1,8 @@ -#!/usr/bin/env bash -# Bash completion support for RVM. +# shellcheck shell=bash +about-completion "Bash completion support for RVM." # Source: https://rvm.io/workflow/completion -[[ -r $rvm_path/scripts/completion ]] && . $rvm_path/scripts/completion +if [[ -n "${rvm_path:-}" && -s "${rvm_path}/scripts/completion" ]]; then + # shellcheck disable=SC1091 + source "${rvm_path}/scripts/completion" +fi diff --git a/completion/available/svn.completion.bash b/completion/available/svn.completion.bash index 2f0a23fe97..8d24066caa 100644 --- a/completion/available/svn.completion.bash +++ b/completion/available/svn.completion.bash @@ -3,13 +3,10 @@ # Locate and load completions for `svn`. # Make sure svn is installed -_command_exists svn || return +_bash-it-completion-helper-necessary svn || : # Don't handle completion if it's already managed -if _completion_exists svn; then - _log_warning "completion already loaded - this usually means it is safe to stop using this completion" - return 0 -fi +_bash-it-completion-helper-sufficient svn || return _svn_bash_completion_xcrun_svn= if _command_exists xcrun; then diff --git a/completion/available/terraform.completion.bash b/completion/available/terraform.completion.bash index 1452fca8b2..8175769bdc 100644 --- a/completion/available/terraform.completion.bash +++ b/completion/available/terraform.completion.bash @@ -1,10 +1,10 @@ -#!/usr/bin/env bash +# shellcheck shell=bash # Make sure terraform is installed -_command_exists terraform || return +_bash-it-completion-helper-necessary terraform || return # Don't handle completion if it's already managed -complete -p terraform &>/dev/null && return +_bash-it-completion-helper-sufficient terraform || return # Terraform completes itself complete -C terraform terraform diff --git a/completion/available/todo.completion.bash b/completion/available/todo.completion.bash index b5517d8654..ed2a48ab9c 100644 --- a/completion/available/todo.completion.bash +++ b/completion/available/todo.completion.bash @@ -1,2 +1,5 @@ +# shellcheck shell=bash + _log_warning 'Bash completion for "todo.txt-cli" is now deprecated, as it used code with incompatible license. Please disable this completion and use the instructions from "todo.txt-cli" developers instead.' +_disable-completion "todo" diff --git a/completion/available/travis.completion.bash b/completion/available/travis.completion.bash index 49d8f2cc92..0a1d0088f4 100644 --- a/completion/available/travis.completion.bash +++ b/completion/available/travis.completion.bash @@ -1,10 +1,13 @@ # shellcheck shell=bash -if _command_exists travis -then - if [[ -s "${__TRAVIS_COMPLETION_SCRIPT:=${TRAVIS_CONFIG_PATH:-${HOME}/.travis}/travis.sh}" ]] - then - source "${__TRAVIS_COMPLETION_SCRIPT}" - fi - unset __TRAVIS_COMPLETION_SCRIPT +# Make sure travis is installed +_bash-it-completion-helper-necessary travis || : + +# Don't handle completion if it's already managed +_bash-it-completion-helper-sufficient travis || return + +if [[ -s "${_travis_bash_completion_script:=${TRAVIS_CONFIG_PATH:-${HOME}/.travis}/travis.sh}" ]]; then + # shellcheck disable=SC1090 + source "${_travis_bash_completion_script}" fi +unset "${!_travis_bash_completion@}" diff --git a/completion/available/vault.completion.bash b/completion/available/vault.completion.bash index 9520f166b1..6ce9d736ac 100644 --- a/completion/available/vault.completion.bash +++ b/completion/available/vault.completion.bash @@ -1,7 +1,10 @@ # shellcheck shell=bash -cite "about-completion" about-completion "vault completion" -if _binary_exists vault; then - complete -C vault vault -fi +# Make sure vault is installed +_bash-it-completion-helper-necessary vault || return + +# Don't handle completion if it's already managed +_bash-it-completion-helper-sufficient vault || return + +complete -C vault vault diff --git a/completion/available/virsh.completion.bash b/completion/available/virsh.completion.bash index 6450b4a305..74967e5d59 100644 --- a/completion/available/virsh.completion.bash +++ b/completion/available/virsh.completion.bash @@ -1,2 +1,5 @@ +# shellcheck shell=bash + _log_warning 'Bash completion for "virsh" is now deprecated, as it used code with incompatible license. Please disable this completion and use the instructions from "virsh" developers instead.' +_disable-completion "virsh" diff --git a/completion/available/vuejs.completion.bash b/completion/available/vuejs.completion.bash index 751658f0c9..b7ee31980e 100644 --- a/completion/available/vuejs.completion.bash +++ b/completion/available/vuejs.completion.bash @@ -1,61 +1,61 @@ # shellcheck shell=bash -__vuejs_completion() { - # shellcheck disable=SC2155 - local prev=$(_get_pword) - # shellcheck disable=SC2155 - local curr=$(_get_cword) +# Make sure vue is installed +_bash-it-completion-helper-necessary vue || : + +# Don't handle completion if it's already managed +_bash-it-completion-helper-sufficient vue || return + +function _vuejs() { + local prev="${COMP_WORDS[COMP_CWORD - 1]}" case $prev in create) - # shellcheck disable=SC2207 - COMPREPLY=($(compgen -W "-p -d -i -m -r -g -n -f -c -x -b -h --help --preset --default --inilinePreset --packageManager --registry --git --no-git --force --merge --clone --proxy --bare --skipGetStarted" -- "$curr")) + COMPREPLY=("-p" "-d" "-i" "-m" "-r" "-g" "-n" "-f" "-c" "-x" "-b" + "-h" "--help" "--preset" "--default" "--inilinePreset" + "--packageManager" "--registry" "--git" "--no-git" "--force" + "--merge" "--clone" "--proxy" "--bare" "" "--skipGetStarted") ;; add | invoke) - # shellcheck disable=SC2207 - COMPREPLY=($(compgen -W "--registry -h --help" -- "$curr")) + COMPREPLY=("--registry" "-h" "--help") ;; inspect) - # shellcheck disable=SC2207 - COMPREPLY=($(compgen -W "-v --help --verbose --mode --rule --plugin --plugins --rules" -- "$curr")) + COMPREPLY=("-v" "--help" "--verbose" "--mode" "--rule" "--plugin" + "--plugins" "--rules") ;; serve) - # shellcheck disable=SC2207 - COMPREPLY=($(compgen -W "-o -h --help --open -c --copy -p --port" -- "$curr")) + COMPREPLY=("-o" "-h" "--help" "--open" "-c" "--copy" "-p" "--port") ;; build) - # shellcheck disable=SC2207 - COMPREPLY=($(compgen -W "-t --target -n --name -d --dest -h --help" -- "$curr")) + COMPREPLY=("-t" "--target" "-n" "--name" "-d" "--dest" "-h" "--help") ;; ui) - # shellcheck disable=SC2207 - COMPREPLY=($(compgen -W "-H --host -p --port -D --dev --quiet --headless -h --help" -- "$curr")) + COMPREPLY=("-H" "--host" "-p" "--port" "-D" "--dev" "--quiet" + "--headless" "-h" "--help") ;; init) - # shellcheck disable=SC2207 - COMPREPLY=($(compgen -W "-c --clone --offline -h --help" -- "$curr")) + COMPREPLY=("-c" "--clone" "--offline" "-h" "--help") ;; config) - # shellcheck disable=SC2207 - COMPREPLY=($(compgen -W "-g --get -s --set -d --delete -e --edit --json -h --help" -- "$curr")) + COMPREPLY=("-g" "--get" "-s" "--set" "-d" "--delete" "-e" "--edit" + "--json" "-h" "--help") ;; outdated) - # shellcheck disable=SC2207 - COMPREPLY=($(compgen -W "--next -h --help" -- "$curr")) + COMPREPLY=("--next" "-h" "--help") ;; upgrade) - # shellcheck disable=SC2207 - COMPREPLY=($(compgen -W "-t --to -f --from -r --registry --all --next -h --help" -- "$curr")) + COMPREPLY=("-t" "--to" "-f" "--from" "-r" "--registry" "--all" + "--next" "-h" "--help") ;; migrate) - # shellcheck disable=SC2207 - COMPREPLY=($(compgen -W "-f --from -h --help" -- "$curr")) + COMPREPLY=("-f" "--from" "-h" "--help") ;; *) - # shellcheck disable=SC2207 - COMPREPLY=($(compgen -W "-h --help -v --version create add invoke inspect serve build ui init config outdated upgrade migrate info" -- "$curr")) + COMPREPLY=("-h" "--help" "-v" "--version" "create" "add" "invoke" + "inspect" "serve" "build" "ui" "init" "config" "outdated" + "upgrade" "migrate" "info") ;; esac } -complete -F __vuejs_completion vue +complete -F _vuejs -X '!&*' vue diff --git a/completion/available/wpscan.completion.bash b/completion/available/wpscan.completion.bash index 105468a356..9c5a95c13b 100644 --- a/completion/available/wpscan.completion.bash +++ b/completion/available/wpscan.completion.bash @@ -1,8 +1,12 @@ # shellcheck shell=bash -_command_exists wpscan || return +# Make sure wpscan is installed +_bash-it-completion-helper-necessary wpscan || : -function __wpscan_completion() { +# Don't handle completion if it's already managed +_bash-it-completion-helper-sufficient wpscan || return + +function __wpscan() { local _opt_ local OPTS=('--help' '--hh' '--version' '--url' '--ignore-main-redirect' '--verbose' '--output' '--format' '--detection-mode' '--scope' '--headers' '--user-agent' '--vhost' '--random-user-agent' '--user-agents-list' '--http-auth' '--max-threads' '--throttle' '--request-timeout' '--connect-timeout' '--disable-tlc-checks' '--proxy' '--proxy-auth' '--cookie-string' '--cookie-jar' '--cache-ttl' '--clear-cache' '--server' '--cache-dir' '--update' '--no-update' '--wp-content-dir' '--wp-plugins-dir' '--wp-version-detection' '--main-theme-detection' '--enumerate' '--exclude-content-based' '--plugins-list' '--plugins-detection' '--plugins-version-all' '--plugins-version-detection' '--themes-list' '--themes-detection' '--themes-version-all' '--themes-version-detection' '--timthumbs-list' '--timthumbs-detection' '--config-backups-list' '--config-backups-detection' '--db-exports-list' '--db-exports-detection' '--medias-detection' '--users-list' '--users-detection' '--passwords' '--usernames' '--multicall-max-passwords' '--password-attack' '--stealthy') COMPREPLY=() @@ -13,4 +17,4 @@ function __wpscan_completion() { done } -complete -F __wpscan_completion wpscan +complete -F __wpscan wpscan diff --git a/lib/completion.bash b/lib/completion.bash new file mode 100644 index 0000000000..fb74f1f94b --- /dev/null +++ b/lib/completion.bash @@ -0,0 +1,49 @@ +# shellcheck shell=bash +# Functions for working with _Bash_'s Programmable Completion + +# +## +# Testing Completion Functions +## +# + +# + +# +## +# Generating Completion Results +## +# + +# + +# +## +# Loading _Bash It_'s Completion Plugins +## + +function _bash-it-completion-helper-necessary() { + local requirement _result=0 + for requirement in "$@"; do + if ! _binary_exists "${requirement}"; then + _result=1 + fi + done + if [[ ${_result} -gt 0 ]]; then + _log_warning "Without '${!#}' installed, this completion won't be too useful." + fi + return "${_result}" +} + +function _bash-it-completion-helper-sufficient() { + local completion _result=0 + for completion in "$@"; do + if _completion_exists "${completion}"; then + _result=1 + fi + done + if [[ ${_result} -gt 0 ]]; then + _log_warning "completion already loaded - this usually means it is safe to stop using this completion." + fi + return "${_result}" +}