From f6c5717a7abf672e37f9367c6473d38b83fcd36f Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sun, 19 Sep 2021 21:52:46 -0700 Subject: [PATCH 01/35] plugins/textmate: use `_command_exists` Addresses bash-it/bash-it#1632 --- clean_files.txt | 1 + plugins/available/textmate.plugin.bash | 8 +++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/clean_files.txt b/clean_files.txt index b8fcee4f..8fdc0c10 100644 --- a/clean_files.txt +++ b/clean_files.txt @@ -86,6 +86,7 @@ plugins/available/goenv.plugin.bash plugins/available/history-search.plugin.bash plugins/available/history-substring-search.plugin.bash plugins/available/history.plugin.bash +plugins/available/textmate.plugin.bash plugins/available/xterm.plugin.bash # tests diff --git a/plugins/available/textmate.plugin.bash b/plugins/available/textmate.plugin.bash index e3538c1e..5c81f195 100644 --- a/plugins/available/textmate.plugin.bash +++ b/plugins/available/textmate.plugin.bash @@ -1,7 +1,9 @@ +# shellcheck shell=bash cite about-plugin about-plugin 'set textmate as a default editor' -if $(command -v mate &> /dev/null) ; then - export EDITOR="$(which mate) -w" - export GIT_EDITOR=$EDITOR +if _command_exists mate; then + EDITOR="$(type -p mate) -w" + GIT_EDITOR="$EDITOR" + export EDITOR GIT_EDITOR fi From a7955b972c2f45e044de925629fb02d89e11593b Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sun, 19 Sep 2021 21:53:59 -0700 Subject: [PATCH 02/35] plugins/powerline: use `_command_exists` Addresses bash-it/bash-it#1632 --- plugins/available/powerline.plugin.bash | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/plugins/available/powerline.plugin.bash b/plugins/available/powerline.plugin.bash index 3d91e658..1927bf3e 100644 --- a/plugins/available/powerline.plugin.bash +++ b/plugins/available/powerline.plugin.bash @@ -1,9 +1,9 @@ -#!/usr/bin/env bash +# shellcheck shell=bash cite about-plugin about-plugin 'enables powerline daemon' -command -v powerline-daemon &>/dev/null || return +_command_exists powerline-daemon || return powerline-daemon -q #the following should not be executed if bashit powerline themes in use @@ -14,13 +14,13 @@ case "$BASH_IT_THEME" in esac POWERLINE_BASH_CONTINUATION=1 POWERLINE_BASH_SELECT=1 -bashPowerlineInit=$(python -c \ +bashPowerlineInit="$(python -c \ "import os; \ import powerline;\ print(os.path.join(os.path.dirname(\ powerline.__file__),\ 'bindings', \ 'bash', \ - 'powerline.sh'))") + 'powerline.sh'))")" [ -e $bashPowerlineInit ] || return -. $bashPowerlineInit +source $bashPowerlineInit From 9378a8318f91b5ae1b11efa11e8e2e33f27215ea Mon Sep 17 00:00:00 2001 From: John D Pell Date: Thu, 9 Sep 2021 16:16:51 -0700 Subject: [PATCH 03/35] plugins/nvm: use `_command_exists` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Addresses bash-it/bash-it#1632 alsö, quote variable, &c. --- plugins/available/nvm.plugin.bash | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/plugins/available/nvm.plugin.bash b/plugins/available/nvm.plugin.bash index 87dce644..0e6da5d8 100644 --- a/plugins/available/nvm.plugin.bash +++ b/plugins/available/nvm.plugin.bash @@ -1,22 +1,23 @@ -# Bash-it no longer bundles nvm, as this was quickly becoming outdated. +# shellcheck shell=bash # # BASH_IT_LOAD_PRIORITY: 225 # +# Bash-it no longer bundles nvm, as this was quickly becoming outdated. # Please install nvm from https://github.com/creationix/nvm.git if you want to use it. cite about-plugin about-plugin 'node version manager configuration' -export NVM_DIR=${NVM_DIR:-$HOME/.nvm} +export NVM_DIR="${NVM_DIR:-$HOME/.nvm}" # This loads nvm -if _bash_it_homebrew_check && [ -s "${BASH_IT_HOMEBREW_PREFIX}/nvm.sh" ] +if _bash_it_homebrew_check && [[ -s "${BASH_IT_HOMEBREW_PREFIX}/nvm.sh" ]] then - . "${BASH_IT_HOMEBREW_PREFIX}/nvm.sh" + source "${BASH_IT_HOMEBREW_PREFIX}/nvm.sh" else - [ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" + [[ -s "$NVM_DIR/nvm.sh" ]] && source "$NVM_DIR/nvm.sh" fi -if ! command -v nvm &>/dev/null +if ! _command_exists nvm then function nvm() { echo "Bash-it no longer bundles the nvm script. Please install the latest version from" From e701660ff161385fd63c10a53a168ff5e18c3404 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sun, 19 Sep 2021 21:54:21 -0700 Subject: [PATCH 04/35] plugins/node: use `_command_exists` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Addresses bash-it/bash-it#1632 alsö, quote variable, use `[[`, &c. --- clean_files.txt | 1 + plugins/available/node.plugin.bash | 11 ++++++----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/clean_files.txt b/clean_files.txt index 8fdc0c10..3f597470 100644 --- a/clean_files.txt +++ b/clean_files.txt @@ -86,6 +86,7 @@ plugins/available/goenv.plugin.bash plugins/available/history-search.plugin.bash plugins/available/history-substring-search.plugin.bash plugins/available/history.plugin.bash +plugins/available/node.plugin.bash plugins/available/textmate.plugin.bash plugins/available/xterm.plugin.bash diff --git a/plugins/available/node.plugin.bash b/plugins/available/node.plugin.bash index 65df3da3..8bf876df 100644 --- a/plugins/available/node.plugin.bash +++ b/plugins/available/node.plugin.bash @@ -1,13 +1,14 @@ +# shellcheck shell=bash cite about-plugin about-plugin 'Node.js helper functions' +# Check that we have npm +_command_exists npm || return + # Ensure local modules are preferred in PATH pathmunge "./node_modules/.bin" "after" -# Check that we have npm -out=$(command -v npm 2>&1) || return - # If not using nodenv, ensure global modules are in PATH -if [[ ! $out == *"nodenv/shims"* ]] ; then - pathmunge "$(npm config get prefix)/bin" "after" +if [[ ! "$(type -p npm)" == *"nodenv/shims"* ]]; then + pathmunge "$(npm config get prefix)/bin" "after" fi From 635e5488ba1bf530e1046968fdb1bdf8873cc461 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sun, 19 Sep 2021 21:58:47 -0700 Subject: [PATCH 05/35] plugins/jump: use `_command_exists` Addresses bash-it/bash-it#1632 --- clean_files.txt | 1 + plugins/available/jump.plugin.bash | 9 ++++++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/clean_files.txt b/clean_files.txt index 3f597470..9c24975b 100644 --- a/clean_files.txt +++ b/clean_files.txt @@ -86,6 +86,7 @@ plugins/available/goenv.plugin.bash plugins/available/history-search.plugin.bash plugins/available/history-substring-search.plugin.bash plugins/available/history.plugin.bash +plugins/available/jump.plugin.bash plugins/available/node.plugin.bash plugins/available/textmate.plugin.bash plugins/available/xterm.plugin.bash diff --git a/plugins/available/jump.plugin.bash b/plugins/available/jump.plugin.bash index 26d6467d..1713d1b7 100644 --- a/plugins/available/jump.plugin.bash +++ b/plugins/available/jump.plugin.bash @@ -1,9 +1,12 @@ +# shellcheck shell=bash +# shellcheck disable=SC2016 cite about-plugin about-plugin 'initialize jump (see https://github.com/gsamokovarov/jump). Add `export JUMP_OPTS=("--bind=z")` to change keybinding' -__init_jump() { - command -v jump &> /dev/null || return - eval "$(jump shell bash "${JUMP_OPTS[@]}")" +function __init_jump() { + if _command_exists jump; then + eval "$(jump shell bash "${JUMP_OPTS[@]}")" + fi } __init_jump From 3e2ec1232d14cacb142e6bab2c16aa00fdab9915 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sun, 19 Sep 2021 21:39:43 -0700 Subject: [PATCH 06/35] plugins/hub: use `_command_exists` Addresses bash-it/bash-it#1632 --- clean_files.txt | 1 + plugins/available/hub.plugin.bash | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/clean_files.txt b/clean_files.txt index 9c24975b..173995c5 100644 --- a/clean_files.txt +++ b/clean_files.txt @@ -86,6 +86,7 @@ plugins/available/goenv.plugin.bash plugins/available/history-search.plugin.bash plugins/available/history-substring-search.plugin.bash plugins/available/history.plugin.bash +plugins/available/hub.plugin.bash plugins/available/jump.plugin.bash plugins/available/node.plugin.bash plugins/available/textmate.plugin.bash diff --git a/plugins/available/hub.plugin.bash b/plugins/available/hub.plugin.bash index 0a67a7af..e9a8cbab 100644 --- a/plugins/available/hub.plugin.bash +++ b/plugins/available/hub.plugin.bash @@ -1,4 +1,7 @@ +# shellcheck shell=bash cite about-plugin about-plugin 'load hub, if you are using it' -command -v hub &> /dev/null && eval "$(hub alias -s)" +if _command_exists hub; then + eval "$(hub alias -s)" +fi From 39d6488c6be8fc3e5c082fd85351b1c36f9247c1 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Thu, 9 Sep 2021 16:17:00 -0700 Subject: [PATCH 07/35] plugins/base: use `_command_exists` Addresses bash-it/bash-it#1632 --- plugins/available/base.plugin.bash | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/available/base.plugin.bash b/plugins/available/base.plugin.bash index 8499a2df..b0899ce9 100644 --- a/plugins/available/base.plugin.bash +++ b/plugins/available/base.plugin.bash @@ -5,10 +5,10 @@ function ips () { about 'display all ip addresses for this host' group 'base' - if command -v ifconfig &>/dev/null + if _command_exists ifconfig then ifconfig | awk '/inet /{ gsub(/addr:/, ""); print $2 }' - elif command -v ip &>/dev/null + elif _command_exists ip then ip addr | grep -oP 'inet \K[\d.]+' else @@ -70,7 +70,7 @@ function passgen () # Create alias pass to passgen when pass isn't installed or # BASH_IT_LEGACY_PASS is true. -if ! command -v pass &>/dev/null || [[ "${BASH_IT_LEGACY_PASS:-}" = true ]] +if ! _command_exists pass || [[ "${BASH_IT_LEGACY_PASS:-}" = true ]] then alias pass=passgen fi @@ -81,7 +81,7 @@ function pmdown () param '1: markdown file' example '$ pmdown README.md' group 'base' - if command -v markdown &>/dev/null + if _command_exists markdown then markdown $1 | browser else From de58fdd73fa6316626080c8b73df3b9a669aa1da Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sun, 19 Sep 2021 21:57:21 -0700 Subject: [PATCH 08/35] plugins/autojump: use `_command_exists` Addresses bash-it/bash-it#1632 --- clean_files.txt | 1 + plugins/available/autojump.plugin.bash | 13 ++++++++----- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/clean_files.txt b/clean_files.txt index 173995c5..26496237 100644 --- a/clean_files.txt +++ b/clean_files.txt @@ -77,6 +77,7 @@ completion/available/wpscan.completion.bash # plugins # plugins/available/alias-completion.plugin.bash +plugins/available/autojump.plugin.bash plugins/available/basher.plugin.bash plugins/available/cmd-returned-notify.plugin.bash plugins/available/docker-machine.plugin.bash diff --git a/plugins/available/autojump.plugin.bash b/plugins/available/autojump.plugin.bash index 7e6df7fc..dc8fbbb4 100644 --- a/plugins/available/autojump.plugin.bash +++ b/plugins/available/autojump.plugin.bash @@ -1,12 +1,15 @@ +# shellcheck shell=bash cite about-plugin about-plugin 'Autojump configuration, see https://github.com/wting/autojump for more details' # Only supports the Homebrew variant, Debian and Arch at the moment. # Feel free to provide a PR to support other install locations if _bash_it_homebrew_check && [[ -s "${BASH_IT_HOMEBREW_PREFIX}/etc/profile.d/autojump.sh" ]]; then - . "${BASH_IT_HOMEBREW_PREFIX}/etc/profile.d/autojump.sh" -elif command -v dpkg &>/dev/null && dpkg -s autojump &>/dev/null ; then - . "$(dpkg-query -S autojump.sh | cut -d' ' -f2)" -elif command -v pacman &>/dev/null && pacman -Q autojump &>/dev/null ; then - . "$(pacman -Ql autojump | grep autojump.sh | cut -d' ' -f2)" + source "${BASH_IT_HOMEBREW_PREFIX}/etc/profile.d/autojump.sh" +elif _command_exists dpkg && dpkg -s autojump &> /dev/null; then + # shellcheck disable=SC1090 + source "$(dpkg-query -S autojump.sh | cut -d' ' -f2)" +elif _command_exists pacman && pacman -Q autojump &> /dev/null; then + # shellcheck disable=SC1090 + source "$(pacman -Ql autojump | grep autojump.sh | cut -d' ' -f2)" fi From e2915df1e5363cf2aa829537bfe1b2e2d0998ab1 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sun, 19 Sep 2021 10:14:42 -0700 Subject: [PATCH 09/35] completions/wpscan: use `_command_exists` Addresses bash-it/bash-it#1632 --- completion/available/wpscan.completion.bash | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/completion/available/wpscan.completion.bash b/completion/available/wpscan.completion.bash index 5d2e2daa..8891ab7f 100644 --- a/completion/available/wpscan.completion.bash +++ b/completion/available/wpscan.completion.bash @@ -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 From 8e169388d237f504a3d6a6dd4452fa516e55db96 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sun, 19 Sep 2021 10:16:54 -0700 Subject: [PATCH 10/35] completions/laravel: use `_command_exists` Addresses bash-it/bash-it#1632 --- completion/available/laravel.completion.bash | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/completion/available/laravel.completion.bash b/completion/available/laravel.completion.bash index 7bd6f223..9298a7bf 100644 --- a/completion/available/laravel.completion.bash +++ b/completion/available/laravel.completion.bash @@ -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 From cace3a591d2dd2612b906ca0c07e03c436c7f82e Mon Sep 17 00:00:00 2001 From: John D Pell Date: Thu, 9 Sep 2021 16:17:10 -0700 Subject: [PATCH 11/35] main: use `_command_exists` Addresses bash-it/bash-it#1632 --- bash_it.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bash_it.sh b/bash_it.sh index 679ffdaf..215c33c7 100755 --- a/bash_it.sh +++ b/bash_it.sh @@ -145,7 +145,7 @@ if [ -e "$HOME/.jekyllconfig" ]; then fi # BASH_IT_RELOAD_LEGACY is set. -if ! command -v reload &> /dev/null && [ -n "${BASH_IT_RELOAD_LEGACY:-}" ]; then +if ! _command_exists reload && [[ -n "${BASH_IT_RELOAD_LEGACY:-}" ]]; then case $OSTYPE in darwin*) alias reload='source ~/.bash_profile' From 757a5bf25bc6135b9d66082bbf5d86c3cac27f58 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Thu, 9 Sep 2021 16:17:12 -0700 Subject: [PATCH 12/35] aliases/vim: use `_command_exists` --- aliases/available/vim.aliases.bash | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/aliases/available/vim.aliases.bash b/aliases/available/vim.aliases.bash index d19057d0..d5dcdc54 100644 --- a/aliases/available/vim.aliases.bash +++ b/aliases/available/vim.aliases.bash @@ -2,11 +2,7 @@ cite 'about-alias' about-alias 'vim abbreviations' -VIM=$(command -v vim) -GVIM=$(command -v gvim) -MVIM=$(command -v mvim) - -if [[ -n $VIM ]]; then +if _command_exists vim; then alias v='$VIM' # open the vim help in fullscreen incorporated from # https://stackoverflow.com/a/4687513 @@ -17,9 +13,9 @@ fi # http://stackoverflow.com/questions/936501/let-gvim-always-run-a-single-instancek case $OSTYPE in darwin*) - [[ -n $MVIM ]] && function mvimt { command mvim --remote-tab-silent "$@" || command mvim "$@"; } + _command_exists mvim && function mvimt { command mvim --remote-tab-silent "$@" || command mvim "$@"; } ;; *) - [[ -n $GVIM ]] && function gvimt { command gvim --remote-tab-silent "$@" || command gvim "$@"; } + _command_exists gvim && function gvimt { command gvim --remote-tab-silent "$@" || command gvim "$@"; } ;; esac From 5eccc59d27a8176f0ed428a351f9cdcaca466a4e Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sat, 11 Sep 2021 17:35:24 -0700 Subject: [PATCH 13/35] completion/git_flow_avh: use `_command_exists` --- completion/available/git_flow_avh.completion.bash | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/completion/available/git_flow_avh.completion.bash b/completion/available/git_flow_avh.completion.bash index 0b73a0be..abb51bf8 100644 --- a/completion/available/git_flow_avh.completion.bash +++ b/completion/available/git_flow_avh.completion.bash @@ -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 From c29eb16dfcc57fef252377a00251712f3448f7df Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sat, 11 Sep 2021 17:36:30 -0700 Subject: [PATCH 14/35] completion/git_flow: use `_command_exists` --- completion/available/git_flow.completion.bash | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/completion/available/git_flow.completion.bash b/completion/available/git_flow.completion.bash index 04f20ccd..7bfc9ef4 100644 --- a/completion/available/git_flow.completion.bash +++ b/completion/available/git_flow.completion.bash @@ -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 From ccd8b52e896f477576b23f03b526897b0e905272 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sun, 19 Sep 2021 10:21:55 -0700 Subject: [PATCH 15/35] plugins/virtualenv: use `_command_exists` --- plugins/available/virtualenv.plugin.bash | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/plugins/available/virtualenv.plugin.bash b/plugins/available/virtualenv.plugin.bash index f1c85987..41d55ddf 100644 --- a/plugins/available/virtualenv.plugin.bash +++ b/plugins/available/virtualenv.plugin.bash @@ -1,12 +1,14 @@ +# shellcheck shell=bash +# # make sure virtualenvwrapper is enabled if available cite about-plugin about-plugin 'virtualenvwrapper and pyenv-virtualenvwrapper helper functions' if _command_exists pyenv; then - pyenv virtualenvwrapper -else - [[ `which virtualenvwrapper.sh` ]] && . virtualenvwrapper.sh + pyenv virtualenvwrapper +elif _command_exists virtualenvwrapper.sh; then + source virtualenvwrapper.sh fi From b14bb4735e597c80603ffe7d8e007d6c8e5260c4 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sat, 11 Sep 2021 18:00:07 -0700 Subject: [PATCH 16/35] plugins/ruby: use `_command_exists` --- plugins/available/ruby.plugin.bash | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/plugins/available/ruby.plugin.bash b/plugins/available/ruby.plugin.bash index 4ab891d9..b1164106 100644 --- a/plugins/available/ruby.plugin.bash +++ b/plugins/available/ruby.plugin.bash @@ -1,9 +1,11 @@ +# shellcheck shell=bash cite about-plugin about-plugin 'ruby and rubygems specific functions and settings' # Make commands installed with 'gem install --user-install' available # ~/.gem/ruby/${RUBY_VERSION}/bin/ -if which ruby >/dev/null && which gem >/dev/null; then +if _command_exists ruby && _command_exists gem +then pathmunge "$(ruby -e 'print Gem.user_dir')/bin" after fi From cff6f3464aab19f333acdcfe855feec435e15d26 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sun, 19 Sep 2021 21:54:33 -0700 Subject: [PATCH 17/35] plugins/rbenv: use `_command_exists` --- clean_files.txt | 1 + plugins/available/rbenv.plugin.bash | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/clean_files.txt b/clean_files.txt index 26496237..f5a63e6c 100644 --- a/clean_files.txt +++ b/clean_files.txt @@ -90,6 +90,7 @@ plugins/available/history.plugin.bash plugins/available/hub.plugin.bash plugins/available/jump.plugin.bash plugins/available/node.plugin.bash +plugins/available/rbenv.plugin.bash plugins/available/textmate.plugin.bash plugins/available/xterm.plugin.bash diff --git a/plugins/available/rbenv.plugin.bash b/plugins/available/rbenv.plugin.bash index 2b01669d..f3605f58 100644 --- a/plugins/available/rbenv.plugin.bash +++ b/plugins/available/rbenv.plugin.bash @@ -1,7 +1,10 @@ +# shellcheck shell=bash cite about-plugin about-plugin 'load rbenv, if you are using it' export RBENV_ROOT="$HOME/.rbenv" pathmunge "$RBENV_ROOT/bin" -[[ `which rbenv 2>/dev/null` ]] && eval "$(rbenv init - bash)" +if _command_exists rbenv; then + eval "$(rbenv init - bash)" +fi From a31145335e34a12bb2cc1a542105e5ee0ae0bba7 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sun, 19 Sep 2021 21:54:44 -0700 Subject: [PATCH 18/35] plugins/pyenv: use `_command_exists` --- clean_files.txt | 1 + plugins/available/pyenv.plugin.bash | 7 +++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/clean_files.txt b/clean_files.txt index f5a63e6c..da7af75c 100644 --- a/clean_files.txt +++ b/clean_files.txt @@ -90,6 +90,7 @@ plugins/available/history.plugin.bash plugins/available/hub.plugin.bash plugins/available/jump.plugin.bash plugins/available/node.plugin.bash +plugins/available/pyenv.plugin.bash plugins/available/rbenv.plugin.bash plugins/available/textmate.plugin.bash plugins/available/xterm.plugin.bash diff --git a/plugins/available/pyenv.plugin.bash b/plugins/available/pyenv.plugin.bash index 4d8db4fb..dc8df3ad 100644 --- a/plugins/available/pyenv.plugin.bash +++ b/plugins/available/pyenv.plugin.bash @@ -1,12 +1,15 @@ +# shellcheck shell=bash cite about-plugin about-plugin 'load pyenv, if you are using it' export PYENV_ROOT="$HOME/.pyenv" pathmunge "$PYENV_ROOT/bin" -[[ `which pyenv 2>/dev/null` ]] && eval "$(pyenv init - bash)" +if _command_exists pyenv; then + eval "$(pyenv init - bash)" +fi #Load pyenv virtualenv if the virtualenv plugin is installed. if pyenv virtualenv-init - &> /dev/null; then - eval "$(pyenv virtualenv-init - bash)" + eval "$(pyenv virtualenv-init - bash)" fi From f0179c79ce3cb035bf8b0ac2725a7339d381cc47 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sun, 19 Sep 2021 21:54:54 -0700 Subject: [PATCH 19/35] plugins/plenv: use `_command_exists` --- clean_files.txt | 1 + plugins/available/plenv.plugin.bash | 18 ++++++++---------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/clean_files.txt b/clean_files.txt index da7af75c..aab0e611 100644 --- a/clean_files.txt +++ b/clean_files.txt @@ -90,6 +90,7 @@ plugins/available/history.plugin.bash plugins/available/hub.plugin.bash plugins/available/jump.plugin.bash plugins/available/node.plugin.bash +plugins/available/plenv.plugin.bash plugins/available/pyenv.plugin.bash plugins/available/rbenv.plugin.bash plugins/available/textmate.plugin.bash diff --git a/plugins/available/plenv.plugin.bash b/plugins/available/plenv.plugin.bash index 1da2d61b..79a9cf49 100644 --- a/plugins/available/plenv.plugin.bash +++ b/plugins/available/plenv.plugin.bash @@ -1,18 +1,16 @@ +# shellcheck shell=bash +# # plugin for plenv cite about-plugin about-plugin 'plenv plugin for Perl' -if [[ -e "${HOME}/.plenv/bin" ]] ; then - - # load plenv bin dir into path if it exists - pathmunge "${HOME}/.plenv/bin" - +if [[ -d "${HOME}/.plenv/bin" ]]; then + # load plenv bin dir into path if it exists + pathmunge "${HOME}/.plenv/bin" fi -if [[ `which plenv` ]] ; then - - # init plenv - eval "$(plenv init - bash)" - +if _command_exists plenv; then + # init plenv + eval "$(plenv init - bash)" fi From b038ea58699679b1d017122bc268bc0dd3d5310a Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sun, 19 Sep 2021 21:47:35 -0700 Subject: [PATCH 20/35] plugins/nodenv: use `_command_exists` --- clean_files.txt | 1 + plugins/available/nodenv.plugin.bash | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/clean_files.txt b/clean_files.txt index aab0e611..cd56b2d0 100644 --- a/clean_files.txt +++ b/clean_files.txt @@ -90,6 +90,7 @@ plugins/available/history.plugin.bash plugins/available/hub.plugin.bash plugins/available/jump.plugin.bash plugins/available/node.plugin.bash +plugins/available/nodenv.plugin.bash plugins/available/plenv.plugin.bash plugins/available/pyenv.plugin.bash plugins/available/rbenv.plugin.bash diff --git a/plugins/available/nodenv.plugin.bash b/plugins/available/nodenv.plugin.bash index 1bbe7fbd..262a57c3 100644 --- a/plugins/available/nodenv.plugin.bash +++ b/plugins/available/nodenv.plugin.bash @@ -1,7 +1,10 @@ +# shellcheck shell=bash cite about-plugin about-plugin 'load nodenv, if you are using it' export NODENV_ROOT="$HOME/.nodenv" pathmunge "$NODENV_ROOT/bin" -[[ `which nodenv` ]] && eval "$(nodenv init - bash)" +if _command_exists nodenv; then + eval "$(nodenv init - bash)" +fi From c98424308abe0f7252aebf9c5ea335acf018e856 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sun, 19 Sep 2021 21:48:13 -0700 Subject: [PATCH 21/35] plugins/direnv: use `_command_exists` --- clean_files.txt | 1 + plugins/available/direnv.plugin.bash | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/clean_files.txt b/clean_files.txt index cd56b2d0..2242ef5e 100644 --- a/clean_files.txt +++ b/clean_files.txt @@ -80,6 +80,7 @@ plugins/available/alias-completion.plugin.bash plugins/available/autojump.plugin.bash plugins/available/basher.plugin.bash plugins/available/cmd-returned-notify.plugin.bash +plugins/available/direnv.plugin.bash plugins/available/docker-machine.plugin.bash plugins/available/git.plugin.bash plugins/available/go.plugin.bash diff --git a/plugins/available/direnv.plugin.bash b/plugins/available/direnv.plugin.bash index 5fd564f5..62788600 100644 --- a/plugins/available/direnv.plugin.bash +++ b/plugins/available/direnv.plugin.bash @@ -1,4 +1,7 @@ +# shellcheck shell=bash cite about-plugin about-plugin 'load direnv, if you are using it: https://direnv.net/' -[ -x "$(which direnv)" ] && eval "$(direnv hook bash)" +if _command_exists direnv; then + eval "$(direnv hook bash)" +fi From ef0c64322fd64f7cafe92e359fd9e3cdf21ed7c8 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sat, 11 Sep 2021 18:00:46 -0700 Subject: [PATCH 22/35] completion/travis: use `_command_exists` --- completion/available/travis.completion.bash | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/completion/available/travis.completion.bash b/completion/available/travis.completion.bash index 28d599aa..49d8f2cc 100644 --- a/completion/available/travis.completion.bash +++ b/completion/available/travis.completion.bash @@ -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 From bb555aefbfb84c7c9c05067b9b0fbf09b143a7ea Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sat, 11 Sep 2021 18:00:59 -0700 Subject: [PATCH 23/35] completion/pew: use `_command_exists` --- completion/available/pew.completion.bash | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/completion/available/pew.completion.bash b/completion/available/pew.completion.bash index 73d62e39..04e67ecb 100644 --- a/completion/available/pew.completion.bash +++ b/completion/available/pew.completion.bash @@ -1 +1,6 @@ -[[ -x "$(which pew)" ]] && source "$(pew shell_config)" +# shellcheck shell=bash + +if _command_exists pew +then + source "$(pew shell_config)" +fi From dca96e0c39b2548234e583a6eb5ce981b682f4f5 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sat, 11 Sep 2021 18:01:54 -0700 Subject: [PATCH 24/35] completion/consul: use `_command_exists` --- completion/available/consul.completion.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/completion/available/consul.completion.bash b/completion/available/consul.completion.bash index 3697ffc5..511cf372 100644 --- a/completion/available/consul.completion.bash +++ b/completion/available/consul.completion.bash @@ -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 From 699d893befaa3ad51ecbb8ce7cff455aa664299c Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sat, 11 Sep 2021 18:02:02 -0700 Subject: [PATCH 25/35] completion/awscli: use `_command_exists` --- completion/available/awscli.completion.bash | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/completion/available/awscli.completion.bash b/completion/available/awscli.completion.bash index 530bdd27..a3041837 100644 --- a/completion/available/awscli.completion.bash +++ b/completion/available/awscli.completion.bash @@ -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 From 6618457f9ed989b5f763e4bda29b7ed9578891e0 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sat, 11 Sep 2021 18:02:17 -0700 Subject: [PATCH 26/35] aliases/general: use `_command_exists` --- aliases/available/general.aliases.bash | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/aliases/available/general.aliases.bash b/aliases/available/general.aliases.bash index 0c7bcd9d..61ebe538 100644 --- a/aliases/available/general.aliases.bash +++ b/aliases/available/general.aliases.bash @@ -30,7 +30,7 @@ then alias grep='grep --color=auto' fi -if which gshuf &> /dev/null +if _command_exists gshuf then alias shuf=gshuf fi @@ -65,7 +65,7 @@ alias -- -='cd -' # Go back alias h='history' # Tree -if [ ! -x "$(which tree 2>/dev/null)" ] +if ! _command_exists tree then alias tree="find . -print | sed -e 's;[^/]*/;|____;g;s;____|; |;g'" fi From 88d66bbfca0b7cc15a2e58ed44444c391d2c0293 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sat, 11 Sep 2021 18:02:24 -0700 Subject: [PATCH 27/35] aliases/curl: use `_command_exists` --- aliases/available/curl.aliases.bash | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/aliases/available/curl.aliases.bash b/aliases/available/curl.aliases.bash index 3ced1bb5..a6b2b344 100644 --- a/aliases/available/curl.aliases.bash +++ b/aliases/available/curl.aliases.bash @@ -6,7 +6,8 @@ about-alias 'Curl aliases for convenience.' # set apt aliases function _set_pkg_aliases() { - if [ -x $(which curl) ]; then + if _command_exists curl + then # follow redirects alias cl='curl -L' # follow redirects, download as original name From 0ad1af8306f0f51c218a682663b13d5a8dda930c Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sat, 11 Sep 2021 18:02:28 -0700 Subject: [PATCH 28/35] aliases/apt: use `_command_exists` --- aliases/available/apt.aliases.bash | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/aliases/available/apt.aliases.bash b/aliases/available/apt.aliases.bash index 2f444931..b7ef274c 100644 --- a/aliases/available/apt.aliases.bash +++ b/aliases/available/apt.aliases.bash @@ -1,4 +1,4 @@ -#!/bin/bash +# shellcheck shell=bash # # -binaryanomaly @@ -8,7 +8,8 @@ about-alias 'Apt and dpkg aliases for Ubuntu and Debian distros.' # set apt aliases function _set_pkg_aliases() { - if [ -x $(which apt) ]; then + if _command_exists apt + then alias apts='apt-cache search' alias aptshow='apt-cache show' alias aptinst='sudo apt-get install -V' From 679d8b10b6776e48843227f0f9327b5a3d7d697e Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sun, 19 Sep 2021 01:16:46 -0700 Subject: [PATCH 29/35] completion/gradle: use `_command_exists` --- completion/available/gradle.completion.bash | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/completion/available/gradle.completion.bash b/completion/available/gradle.completion.bash index 6ec8c697..786450a6 100644 --- a/completion/available/gradle.completion.bash +++ b/completion/available/gradle.completion.bash @@ -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" From 699720fe8bca6aa301a80c7eb244551806926eee Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sun, 19 Sep 2021 21:28:32 -0700 Subject: [PATCH 30/35] completion/docker-compose: use `_command_exists` --- completion/available/docker-compose.completion.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) mode change 100644 => 100755 completion/available/docker-compose.completion.bash diff --git a/completion/available/docker-compose.completion.bash b/completion/available/docker-compose.completion.bash old mode 100644 new mode 100755 index bf2c13fb..1102f5d9 --- a/completion/available/docker-compose.completion.bash +++ b/completion/available/docker-compose.completion.bash @@ -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 From 8e9438d7159c677ef4b7691c6842bc6bdbb164ac Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sun, 19 Sep 2021 21:30:35 -0700 Subject: [PATCH 31/35] completion/hub: use `_command_exists` --- completion/available/hub.completion.bash | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/completion/available/hub.completion.bash b/completion/available/hub.completion.bash index 74c530a8..67a5e29b 100644 --- a/completion/available/hub.completion.bash +++ b/completion/available/hub.completion.bash @@ -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/')" From eabdf41b833609bea386f21ebe8200198b48dbb3 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sun, 19 Sep 2021 21:32:19 -0700 Subject: [PATCH 32/35] lib/theme: use `_command_exists` --- themes/base.theme.bash | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/themes/base.theme.bash b/themes/base.theme.bash index 1e0409d3..f9f5190d 100644 --- a/themes/base.theme.bash +++ b/themes/base.theme.bash @@ -396,7 +396,7 @@ function hg_prompt_vars { function nvm_version_prompt { local node - if declare -f -F nvm &> /dev/null; then + if _is_function nvm; then node=$(nvm current 2> /dev/null) [[ "${node}" == "system" ]] && return echo -e "${NVM_THEME_PROMPT_PREFIX}${node}${NVM_THEME_PROMPT_SUFFIX}" @@ -433,8 +433,8 @@ function rbfu_version_prompt { } function chruby_version_prompt { - if declare -f -F chruby &> /dev/null; then - if declare -f -F chruby_auto &> /dev/null; then + if _is_function chruby; then + if _is_function chruby_auto; then chruby_auto fi From a2e32f37c55362960e0ad89d56c1715a5867cfbc Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sun, 19 Sep 2021 21:32:52 -0700 Subject: [PATCH 33/35] theme/dulcie: use `_command_exists` --- themes/dulcie/dulcie.theme.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) mode change 100644 => 100755 themes/dulcie/dulcie.theme.bash diff --git a/themes/dulcie/dulcie.theme.bash b/themes/dulcie/dulcie.theme.bash old mode 100644 new mode 100755 index a83b62fb..f70c7864 --- a/themes/dulcie/dulcie.theme.bash +++ b/themes/dulcie/dulcie.theme.bash @@ -77,7 +77,7 @@ dulcie_prompt() { printf "\033]0;%s@%s:%s\007" "${USER}" "${HOSTNAME%%.*}" "${PWD/#$HOME/\~}" # Open the new terminal in the same directory - declare -f __vte_osc7 > /dev/null && __vte_osc7 + _is_function __vte_osc7 && __vte_osc7 PS1="${reset_color}[${DULCIE_USER}@${DULCIE_HOST}$(scm_prompt_info)${reset_color} ${DULCIE_WORKINGDIR}]" if [[ "${DULCIE_MULTILINE}" -eq "1" ]]; then From 8a03f451b2669faf4fa98b99978e8ba570948613 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sun, 19 Sep 2021 01:26:02 -0700 Subject: [PATCH 34/35] lib/helpers: simplify `_command_exists()` and `_binary_exists()` Remove subshell and just use a regular `if` --- lib/helpers.bash | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) mode change 100644 => 100755 lib/helpers.bash diff --git a/lib/helpers.bash b/lib/helpers.bash old mode 100644 new mode 100755 index 61705a04..fbc6aa88 --- a/lib/helpers.bash +++ b/lib/helpers.bash @@ -23,7 +23,13 @@ function _command_exists () _example '$ _command_exists ls && echo exists' _group 'lib' local msg="${2:-Command '$1' does not exist!}" - type "$1" &> /dev/null || (_log_warning "$msg" && return 1) ; + if type -t "$1" &> /dev/null + then + return 0 + else + _log_warning "$msg" + return 1 + fi } function _binary_exists () @@ -34,7 +40,13 @@ function _binary_exists () _example '$ _binary_exists ls && echo exists' _group 'lib' local msg="${2:-Binary '$1' does not exist!}" - type -P "$1" &> /dev/null || (_log_warning "$msg" && return 1) ; + if type -P "$1" &> /dev/null + then + return 0 + else + _log_warning "$msg" + return 1 + fi } function _completion_exists () From fb6e05d91528bf83175f92b5481d0ee6d6a88c39 Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sun, 19 Sep 2021 10:39:19 -0700 Subject: [PATCH 35/35] completions/sqlmap: use `_command_exists` Addresses bash-it/bash-it#1632 --- completion/available/sqlmap.completion.bash | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/completion/available/sqlmap.completion.bash b/completion/available/sqlmap.completion.bash index 16addf85..213dd817 100644 --- a/completion/available/sqlmap.completion.bash +++ b/completion/available/sqlmap.completion.bash @@ -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[@]}" ) )