Skip to content

Commit

Permalink
completions: clear and consistent log messages
Browse files Browse the repository at this point in the history
TODO: `pew`
TODO: `source <(flutter bash-completion)` vs `eval $(flutter bash-completion)`...saves a subshell...
  • Loading branch information
gaelicWizard committed Jan 26, 2022
1 parent 37148ce commit 751ee02
Show file tree
Hide file tree
Showing 39 changed files with 390 additions and 122 deletions.
4 changes: 2 additions & 2 deletions completion/available/apm.completion.bash
Original file line number Diff line number Diff line change
@@ -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"
17 changes: 14 additions & 3 deletions completion/available/awless.completion.bash
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# shellcheck shell=bash
if _command_exists awless; then
# shellcheck disable=SC1090
source <(awless completion bash)

# Make sure awless is installed
if ! _binary_exists awless; then
_log_warning "Without '$_' installed, this completion won't be too useful."
return 1
fi

# Don't handle completion if it's already managed
if _completion_exists awless; then
_log_warning "completion already loaded - this usually means it is safe to stop using this completion"
return 0
fi

# shellcheck disable=SC1090
source <(awless completion bash)
14 changes: 11 additions & 3 deletions completion/available/awscli.completion.bash
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
# shellcheck shell=bash

if _command_exists aws_completer
then
complete -C "$(command -v aws_completer)" aws
# Make sure aws is installed
if ! _binary_exists aws_completer || ! _binary_exists aws; then
_log_warning "Without '$_' installed, this completion won't be too useful."
fi

# Don't handle completion if it's already managed
if _completion_exists aws; then
_log_warning "completion already loaded - this usually means it is safe to stop using this completion"
return 0
fi

complete -C aws_completer aws
16 changes: 13 additions & 3 deletions completion/available/cargo.completion.bash
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
# 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)"
# Make sure cargo is installed
if ! _binary_exists rustup || ! _binary_exists cargo; then
_log_warning "Without '$_' installed, this completion won't be too useful."
return 1
fi

# Don't handle completion if it's already managed
if _completion_exists cargo; then
_log_warning "completion already loaded - this usually means it is safe to stop using this completion"
return 0
fi

eval "$(rustup completions bash cargo)"
1 change: 0 additions & 1 deletion completion/available/conda.completion.bash
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# shellcheck shell=bash
cite "about-completion"
about-completion "conda completion"

if _command_exists conda; then
Expand Down
15 changes: 12 additions & 3 deletions completion/available/consul.completion.bash
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
# shellcheck shell=bash
cite "about-completion"
about-completion "Hashicorp consul completion"

if _command_exists consul; then
complete -C "$(command -v consul)" consul
# Make sure consul is installed
if ! _binary_exists consul; then
_log_warning "Without '$_' installed, this completion won't be too useful."
return 1
fi

# Don't handle completion if it's already managed
if _completion_exists consul; then
_log_warning "completion already loaded - this usually means it is safe to stop using this completion"
return 0
fi

complete -C consul consul
5 changes: 4 additions & 1 deletion completion/available/crystal.completion.bash
Original file line number Diff line number Diff line change
@@ -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"
5 changes: 3 additions & 2 deletions completion/available/defaults.completion.bash
Original file line number Diff line number Diff line change
@@ -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
29 changes: 21 additions & 8 deletions completion/available/docker.completion.bash
Original file line number Diff line number Diff line change
@@ -1,24 +1,37 @@
# shellcheck shell=bash
cite "about-completion"
about-completion "docker completion"

# Make sure docker is installed
_command_exists docker || return
if ! _binary_exists docker; then
_log_warning "Without '$_' installed, this completion won't be too useful."
fi

# Don't handle completion if it's already managed
_completion_exists docker && return
if _completion_exists docker; then
_log_warning "completion already loaded - this usually means it is safe to stop using this completion"
return 0
fi

_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@}"
1 change: 1 addition & 0 deletions completion/available/drush.completion.bash
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# 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.'
16 changes: 13 additions & 3 deletions completion/available/flutter.completion.bash
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
#!/usr/bin/bash
# shellcheck shell=bash

if _command_exists flutter; then
eval "$(flutter bash-completion)"
# Make sure flutter is installed
if ! _binary_exists flutter; then
_log_warning "Without '$_' installed, this completion won't be too useful."
return 1
fi

# Don't handle completion if it's already managed
if _completion_exists flutter; then
_log_warning "completion already loaded - this usually means it is safe to stop using this completion"
return 0
fi

eval "$(flutter bash-completion)"
1 change: 0 additions & 1 deletion completion/available/gcloud.completion.bash
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# shellcheck shell=bash
cite "about-completion"
about-completion "Google Cloud SDK completion"

if _command_exists gcloud; then
Expand Down
16 changes: 11 additions & 5 deletions completion/available/github-cli.completion.bash
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
# 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)"
if ! _binary_exists gh; then
_log_warning "Without '$_' installed, this completion won't be too useful."
return 1
fi

# Don't handle completion if it's already managed
if _completion_exists gh; then
_log_warning "completion already loaded - this usually means it is safe to stop using this completion"
return 0
fi

eval "$(gh completion --shell=bash)"
15 changes: 12 additions & 3 deletions completion/available/helm.completion.bash
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
# shellcheck shell=bash
cite "about-completion"
about-completion "helm (Kubernetes Package Manager) completion"

if _command_exists helm; then
eval "$(helm completion bash)"
# Make sure helm is installed
if ! _binary_exists helm; then
_log_warning "Without '$_' installed, this completion won't be too useful."
return 1
fi

# Don't handle completion if it's already managed
if _completion_exists helm; then
_log_warning "completion already loaded - this usually means it is safe to stop using this completion"
return 0
fi

eval "$(helm completion bash)"
1 change: 1 addition & 0 deletions completion/available/homesick.completion.bash
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# 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.'
15 changes: 12 additions & 3 deletions completion/available/jungle.completion.bash
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
# shellcheck shell=bash
cite "about-completion"
about-completion "jungle(AWS cli tool) completion"

if _command_exists jungle; then
eval "$(_JUNGLE_COMPLETE=source jungle)"
# Make sure jungle is installed
if ! _binary_exists jungle; then
_log_warning "Without '$_' installed, this completion won't be too useful."
return 1
fi

# Don't handle completion if it's already managed
if _completion_exists jungle; then
_log_warning "completion already loaded - this usually means it is safe to stop using this completion"
return 0
fi

eval "$(_JUNGLE_COMPLETE=source jungle)"
16 changes: 13 additions & 3 deletions completion/available/kind.completion.bash
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
#!/usr/bin/env bash
# shellcheck shell=bash

if _command_exists kind; then
eval "$(kind completion bash)"
# Make sure kind is installed
if ! _binary_exists kind; then
_log_warning "Without '$_' installed, this completion won't be too useful."
return 1
fi

# Don't handle completion if it's already managed
if _completion_exists kind; then
_log_warning "completion already loaded - this usually means it is safe to stop using this completion"
return 0
fi

eval "$(kind completion bash)"
17 changes: 14 additions & 3 deletions completion/available/kontena.completion.bash
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# shellcheck shell=bash
if _command_exists kontena; then
# shellcheck disable=SC1090
source "$(kontena whoami --bash-completion-path)"

# Make sure kontena is installed
if ! _binary_exists kontena; then
_log_warning "Without '$_' installed, this completion won't be too useful."
return 1
fi

# Don't handle completion if it's already managed
if _completion_exists kontena; then
_log_warning "completion already loaded - this usually means it is safe to stop using this completion"
return 0
fi

# shellcheck disable=SC1090
source "$(kontena whoami --bash-completion-path)"
15 changes: 12 additions & 3 deletions completion/available/kubectl.completion.bash
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
# shellcheck shell=bash
cite "about-completion"
about-completion "kubectl (Kubernetes CLI) completion"

if _binary_exists kubectl; then
eval "$(kubectl completion bash)"
# Make sure kubectl is installed
if ! _binary_exists kubectl; then
_log_warning "Without '$_' installed, this completion won't be too useful."
return 1
fi

# Don't handle completion if it's already managed
if _completion_exists kubectl; then
_log_warning "completion already loaded - this usually means it is safe to stop using this completion"
return 0
fi

eval "$(kubectl completion bash)"
11 changes: 10 additions & 1 deletion completion/available/laravel.completion.bash
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
# shellcheck shell=bash

_command_exists laravel || return
# Make sure laravel is installed
if ! _binary_exists laravel; then
_log_warning "Without '$_' installed, this completion won't be too useful."
fi

# Don't handle completion if it's already managed
if _completion_exists laravel; then
_log_warning "completion already loaded - this usually means it is safe to stop using this completion"
return 0
fi

function __laravel_completion() {
local OPTS=('-h' '--help' '-q' '--quiet' '--ansi' '--no-ansi' '-n' '--no-interaction' '-v' '-vv' '-vvv' '--verbose' 'help' 'list' 'new')
Expand Down
44 changes: 23 additions & 21 deletions completion/available/makefile.completion.bash
Original file line number Diff line number Diff line change
@@ -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
Expand Down
16 changes: 13 additions & 3 deletions completion/available/minikube.completion.bash
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
# shellcheck shell=bash
# minikube (Local Kubernetes) completion
about-completion "minikube (Local Kubernetes) completion"

if _command_exists minikube; then
eval "$(minikube completion bash)"
# Make sure minikube is installed
if ! _binary_exists minikube; then
_log_warning "Without '$_' installed, this completion won't be too useful."
return 1
fi

# Don't handle completion if it's already managed
if _completion_exists minikube; then
_log_warning "completion already loaded - this usually means it is safe to stop using this completion"
return 0
fi

eval "$(minikube completion bash)"
Loading

0 comments on commit 751ee02

Please sign in to comment.