From 4fb778c4055b55b3f43683813fd4b2c2c3d98891 Mon Sep 17 00:00:00 2001 From: M Date: Fri, 24 Sep 2021 04:29:09 -0700 Subject: [PATCH] Refactor "{{which,command -v} => _omb_util_{binary,command}_exists}" `which` has been deprecated in Debian (at least, the rolling release installed on chromebooks via Linux Containers) https://github.com/ohmybash/oh-my-bash/pull/239#issuecomment-1000974461 Co-authored-by: Koichi Murase --- completions/awscli.completion.sh | 2 +- completions/conda.completion.sh | 2 +- completions/django.completion.sh | 2 +- completions/docker.completion.sh | 2 +- completions/drush.completion.sh | 2 +- completions/fabric-completion.sh | 2 +- completions/jungle.completion.sh | 2 +- completions/kontena.completion.sh | 2 +- completions/kubectl.completion.sh | 2 +- completions/minikube.completion.sh | 2 +- completions/npm.completion.sh | 2 +- completions/system.completion.sh | 2 +- lib/base.sh | 4 ++-- lib/misc.sh | 2 +- lib/omb-prompt-base.sh | 4 ++-- themes/brainy/brainy.theme.sh | 4 ++-- tools/autossh.sh | 2 +- 17 files changed, 20 insertions(+), 20 deletions(-) diff --git a/completions/awscli.completion.sh b/completions/awscli.completion.sh index 85777fe..4495c21 100644 --- a/completions/awscli.completion.sh +++ b/completions/awscli.completion.sh @@ -1,2 +1,2 @@ #! bash oh-my-bash.module -[[ -x "$(which aws_completer)" ]] &>/dev/null && complete -C "$(which aws_completer)" aws +_omb_util_binary_exists aws_completer && complete -C "$(type -P aws_completer)" aws diff --git a/completions/conda.completion.sh b/completions/conda.completion.sh index e43f8ff..29222d8 100644 --- a/completions/conda.completion.sh +++ b/completions/conda.completion.sh @@ -1,4 +1,4 @@ #! bash oh-my-bash.module -which register-python-argcomplete &> /dev/null \ +_omb_util_binary_exists register-python-argcomplete \ && eval "$(register-python-argcomplete conda)" \ || echo "Please install argcomplete to use conda completion" > /dev/null diff --git a/completions/django.completion.sh b/completions/django.completion.sh index e35dd1e..24a5b73 100644 --- a/completions/django.completion.sh +++ b/completions/django.completion.sh @@ -59,7 +59,7 @@ _python_django_completion() # Support for multiple interpreters. unset pythons -if command -v whereis &>/dev/null; then +if _omb_util_command_exists whereis; then python_interpreters=$(whereis python | cut -d " " -f 2-) for python in $python_interpreters; do pythons="${pythons} $(basename -- $python)" diff --git a/completions/docker.completion.sh b/completions/docker.completion.sh index e34d237..8daab5e 100644 --- a/completions/docker.completion.sh +++ b/completions/docker.completion.sh @@ -410,7 +410,7 @@ __docker_nospace() { } __docker_complete_resolved_hostname() { - command -v host >/dev/null 2>&1 || return + _omb_util_command_exists host || return COMPREPLY=( $(host 2>/dev/null "${cur%:}" | awk '/has address/ {print $4}') ) } diff --git a/completions/drush.completion.sh b/completions/drush.completion.sh index 29205c1..b3232e0 100644 --- a/completions/drush.completion.sh +++ b/completions/drush.completion.sh @@ -7,7 +7,7 @@ # http://github.com/drush-ops/drush/blob/master/drush.complete.sh # Ensure drush is available. -which drush &> /dev/null || alias drush &> /dev/null || return +_omb_util_command_exists drush || return __drush_ps1() { f="${TMPDIR:-/tmp/}/drush-env/drush-drupal-site-$$" diff --git a/completions/fabric-completion.sh b/completions/fabric-completion.sh index 2de2a9d..4653a46 100644 --- a/completions/fabric-completion.sh +++ b/completions/fabric-completion.sh @@ -80,7 +80,7 @@ function __fab_fabfile_mtime() { # function __fab_completion() { # Return if "fab" command doesn't exists - [[ -e `which fab 2> /dev/null` ]] || return 0 + _omb_util_binary_exists fab || return 0 # Variables to hold the current word and possible matches local cur="${COMP_WORDS[COMP_CWORD]}" diff --git a/completions/jungle.completion.sh b/completions/jungle.completion.sh index d682bb6..c5d419c 100644 --- a/completions/jungle.completion.sh +++ b/completions/jungle.completion.sh @@ -1,2 +1,2 @@ #! bash oh-my-bash.module -[[ -x "$(which jungle)" ]] &>/dev/null && eval "$(_JUNGLE_COMPLETE=source jungle)" +_omb_util_binary_exists jungle && eval "$(_JUNGLE_COMPLETE=source jungle)" diff --git a/completions/kontena.completion.sh b/completions/kontena.completion.sh index 67c4ad0..e8aac88 100644 --- a/completions/kontena.completion.sh +++ b/completions/kontena.completion.sh @@ -1,2 +1,2 @@ #! bash oh-my-bash.module -which kontena &> /dev/null && . "$( kontena whoami --bash-completion-path )" +_omb_util_binary_exists kontena && . "$( kontena whoami --bash-completion-path )" diff --git a/completions/kubectl.completion.sh b/completions/kubectl.completion.sh index 63fd045..a828c24 100644 --- a/completions/kubectl.completion.sh +++ b/completions/kubectl.completion.sh @@ -2,7 +2,7 @@ # kubectl (Kubernetes CLI) completion -if command -v kubectl &>/dev/null +if _omb_util_command_exists kubectl then eval "$(kubectl completion bash)" fi diff --git a/completions/minikube.completion.sh b/completions/minikube.completion.sh index 73d2cc0..2509c2e 100644 --- a/completions/minikube.completion.sh +++ b/completions/minikube.completion.sh @@ -2,7 +2,7 @@ # minikube (Kubernetes CLI) completion -if command -v minikube &>/dev/null +if _omb_util_command_exists minikube then eval "$(minikube completion bash)" fi diff --git a/completions/npm.completion.sh b/completions/npm.completion.sh index 1eb689e..109460b 100644 --- a/completions/npm.completion.sh +++ b/completions/npm.completion.sh @@ -3,7 +3,7 @@ # npm (Node Package Manager) completion # https://docs.npmjs.com/cli/completion -if command -v npm &>/dev/null +if _omb_util_command_exists npm then eval "$(npm completion)" fi diff --git a/completions/system.completion.sh b/completions/system.completion.sh index 57a5733..24743d1 100644 --- a/completions/system.completion.sh +++ b/completions/system.completion.sh @@ -13,7 +13,7 @@ if [ -f /etc/profile.d/bash_completion.sh ]; then fi -if [ $(uname) = "Darwin" ] && command -v brew &>/dev/null ; then +if [ $(uname) = "Darwin" ] && _omb_util_command_exists brew; then BREW_PREFIX=$(brew --prefix) if [ -f "$BREW_PREFIX"/etc/bash_completion ]; then diff --git a/lib/base.sh b/lib/base.sh index da7f857..a9ff6a2 100644 --- a/lib/base.sh +++ b/lib/base.sh @@ -197,10 +197,10 @@ bigfind() { # ips: display all ip addresses for this host # ------------------------------------------------------------------- ips () { - if command -v ifconfig &>/dev/null + if _omb_util_command_exists ifconfig then ifconfig | awk '/inet /{ print $2 }' - elif command -v ip &>/dev/null + elif _omb_util_command_exists ip then ip addr | grep -oP 'inet \K[\d.]+' else diff --git a/lib/misc.sh b/lib/misc.sh index fb5782c..53d7232 100644 --- a/lib/misc.sh +++ b/lib/misc.sh @@ -11,7 +11,7 @@ _omb_util_alias _='sudo' _omb_util_alias please='sudo' ## more intelligent acking for ubuntu users -if which ack-grep &> /dev/null; then +if _omb_util_binary_exists ack-grep; then _omb_util_alias afind='ack-grep -il' else _omb_util_alias afind='ack -il' diff --git a/lib/omb-prompt-base.sh b/lib/omb-prompt-base.sh index 447ecb4..54ebc27 100644 --- a/lib/omb-prompt-base.sh +++ b/lib/omb-prompt-base.sh @@ -104,9 +104,9 @@ function _omb_prompt_format { function scm { if [[ "$SCM_CHECK" = false ]]; then SCM=$SCM_NONE elif [[ -f .git/HEAD ]]; then SCM=$SCM_GIT - elif which git &> /dev/null && [[ -n "$(git rev-parse --is-inside-work-tree 2> /dev/null)" ]]; then SCM=$SCM_GIT + elif _omb_util_binary_exists git && [[ -n "$(git rev-parse --is-inside-work-tree 2> /dev/null)" ]]; then SCM=$SCM_GIT elif [[ -d .hg ]]; then SCM=$SCM_HG - elif which hg &> /dev/null && [[ -n "$(hg root 2> /dev/null)" ]]; then SCM=$SCM_HG + elif _omb_util_binary_exists hg && [[ -n "$(hg root 2> /dev/null)" ]]; then SCM=$SCM_HG elif [[ -d .svn ]]; then SCM=$SCM_SVN else SCM=$SCM_NONE fi diff --git a/themes/brainy/brainy.theme.sh b/themes/brainy/brainy.theme.sh index a44a267..6a96ff7 100644 --- a/themes/brainy/brainy.theme.sh +++ b/themes/brainy/brainy.theme.sh @@ -135,8 +135,8 @@ ___brainy_prompt_ruby() { } ___brainy_prompt_todo() { - [ "${THEME_SHOW_TODO}" != "true" ] || - [ -z "$(which todo.sh)" ] && return + [ "${THEME_SHOW_TODO}" != "true" ] && return + _omb_util_binary_exists todo.sh || return color=$_omb_prompt_bold_white box="[|]" info="t:$(todo.sh ls | egrep "TODO: [0-9]+ of ([0-9]+)" | awk '{ print $4 }' )" diff --git a/tools/autossh.sh b/tools/autossh.sh index 20712d0..409ea7f 100644 --- a/tools/autossh.sh +++ b/tools/autossh.sh @@ -16,7 +16,7 @@ ALIVE=0 HISTFILE="$HOME/.autossh.history" # Use colors, but only if connected to a terminal, and that terminal supports them. -if which tput >/dev/null 2>&1; then +if type -P tput >/dev/null 2>&1; then ncolors=$(tput colors) fi if [ -t 1 ] && [ -n "$ncolors" ] && [ "$ncolors" -ge 8 ]; then