Merge pull request #1938 from gaelicWizard/_command_exists

Use `_command_exists` everywhere
This commit is contained in:
Noah Gorny
2021-09-20 14:56:45 +03:00
committed by GitHub
36 changed files with 163 additions and 96 deletions

View File

@@ -1 +1,6 @@
[[ -x "$(which aws_completer)" ]] && complete -C "$(which aws_completer)" aws
# shellcheck shell=bash
if _command_exists aws_completer
then
complete -C "$(command -v aws_completer)" aws
fi

View File

@@ -3,5 +3,5 @@ cite "about-completion"
about-completion "Hashicorp consul completion"
if _command_exists consul; then
complete -C "$(which consul)" consul
complete -C "$(command -v consul)" consul
fi

2
completion/available/docker-compose.completion.bash Normal file → Executable file
View File

@@ -676,7 +676,7 @@ _docker_compose() {
done
local completions_func=_docker_compose_${command//-/_}
declare -F $completions_func >/dev/null && $completions_func
_is_function $completions_func && $completions_func
eval "$previous_extglob_setting"
return 0

View File

@@ -172,6 +172,7 @@ __git_flow_list_hotfixes ()
}
# temporarily wrap __git_find_on_cmdline() for backwards compatibility
if [ -z "`type -t __git_find_subcommand`" ]; then
if ! _command_exists __git_find_subcommand
then
alias __git_find_subcommand=__git_find_on_cmdline
fi

View File

@@ -505,6 +505,7 @@ __git_flow_list_branches ()
}
# alias __git_find_on_cmdline for backwards compatibility
if [ -z "`type -t __git_find_on_cmdline`" ]; then
if ! _command_exists __git_find_on_cmdline
then
alias __git_find_on_cmdline=__git_find_subcommand
fi

View File

@@ -58,9 +58,9 @@ __gradle-set-cache-name() {
__gradle-set-files-checksum() {
# Cache MD5 sum of all Gradle scripts and modified timestamps
if builtin command -v md5 > /dev/null; then
if _command_exists md5; then
gradle_files_checksum=$(md5 -q -s "$(cat "$cache_dir/$cache_name" | xargs ls -o 2>/dev/null)")
elif builtin command -v md5sum > /dev/null; then
elif _command_exists md5sum; then
gradle_files_checksum=$(cat "$cache_dir/$cache_name" | xargs ls -o 2>/dev/null | md5sum | awk '{print $1}')
else
echo "Cannot generate completions as neither md5 nor md5sum exist on \$PATH"

View File

@@ -23,12 +23,12 @@
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
# If there is no git tab completion, but we have the _completion loader try to load it
if ! declare -F _git > /dev/null && declare -F _completion_loader > /dev/null; then
if ! _is_function _git && _is_function _completion_loader; then
_completion_loader git
fi
# Check that git tab completion is available and we haven't already set up completion
if declare -F _git > /dev/null && ! declare -F __git_list_all_commands_without_hub > /dev/null; then
if _is_function _git && ! _is_function __git_list_all_commands_without_hub; then
# Duplicate and rename the 'list_all_commands' function
eval "$(declare -f __git_list_all_commands | \
sed 's/__git_list_all_commands/__git_list_all_commands_without_hub/')"

View File

@@ -1,7 +1,9 @@
#!/usr/bin/bash
if command -v laravel > /dev/null; then
__laravel_completion() {
if _command_exists laravel
then
function __laravel_completion()
{
local OPTS=("-h --help -q --quiet --ansi --no-ansi -n --no-interaction -v -vv -vvv --verbose help list new")
COMPREPLY=()
for _opt_ in ${OPTS[@]}; do
@@ -9,7 +11,7 @@ if command -v laravel > /dev/null; then
COMPREPLY+=("$_opt_")
fi
done
}
}
complete -F __laravel_completion laravel
fi

View File

@@ -1 +1,6 @@
[[ -x "$(which pew)" ]] && source "$(pew shell_config)"
# shellcheck shell=bash
if _command_exists pew
then
source "$(pew shell_config)"
fi

View File

@@ -1,21 +1,22 @@
#!/bin/bash
# shellcheck shell=bash
# ---------------------------------------------------------------------------+
# |
# Thanks to Alexander Korznikov |
# Thanks to Alexander Korznikov |
# http://www.korznikov.com/2014/12/bash-tab-completion-for-awesome-tool.html |
# |
# ---------------------------------------------------------------------------+
if command -v sqlmap > /dev/null; then
if _command_exists sqlmap
then
_sqlmap()
function _sqlmap()
{
local cur prev
COMPREPLY=()
cur=$(_get_cword)
prev=$(_get_pword)
cur="$(_get_cword)"
prev="$(_get_pword)"
case $prev in
@@ -143,7 +144,7 @@ if command -v sqlmap > /dev/null; then
--mobile --page-rank --purge-output --smart \
--sqlmap-shell --wizard '
COMPREPLY=( $( \
(while read -d ' ' i; do
(while read -d ' ' i; do
[[ -z "$i" || "${onlyonce/ ${i%% *} / }" == "$onlyonce" ]] &&
continue
# flatten array with spaces on either side,
@@ -152,7 +153,7 @@ if command -v sqlmap > /dev/null; then
COMPREPLY=" ${COMPREPLY[@]} "
# remove word from list of completions
COMPREPLY=( ${COMPREPLY/ ${i%% *} / } )
done
done
printf '%s ' "${COMPREPLY[@]}") <<<"${COMP_WORDS[@]}"
) )

View File

@@ -1,5 +1,10 @@
if [[ -x "$(which travis)" ]]; then
__TRAVIS_COMPLETION_SCRIPT="${TRAVIS_CONFIG_PATH:-${HOME}/.travis}/travis.sh"
[[ -f "${__TRAVIS_COMPLETION_SCRIPT}" ]] && source "${__TRAVIS_COMPLETION_SCRIPT}"
# 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
fi

View File

@@ -1,7 +1,7 @@
# shellcheck shell=bash
if command -v wpscan > /dev/null; then
__wpscan_completion() {
if _command_exists wpscan; then
function __wpscan_completion() {
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=()
for _opt_ in "${OPTS[@]}"; do