lib/helpers: simplify _command_exists() and _binary_exists()

Remove subshell and just use a regular `if`
This commit is contained in:
John D Pell
2021-09-19 01:26:02 -07:00
parent a2e32f37c5
commit 8a03f451b2

16
lib/helpers.bash Normal file → Executable file
View File

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