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 <myoga.murase@gmail.com>
This commit is contained in:
M 2021-09-24 04:29:09 -07:00 committed by Koichi Murase
parent f52647d6d6
commit 4fb778c405
17 changed files with 20 additions and 20 deletions

View File

@ -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

View File

@ -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

View File

@ -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)"

View File

@ -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}') )
}

View File

@ -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-$$"

View File

@ -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]}"

View File

@ -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)"

View File

@ -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 )"

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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'

View File

@ -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

View File

@ -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 }' )"

View File

@ -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