Skip to content

Commit 213c8c7

Browse files
committed
lib/helpers: _command_exists()
The weird subshell is weird AF. Just do a normal `if`. Ditto `_binary_exists()`.
1 parent 66d2c4e commit 213c8c7

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

lib/helpers.bash

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,14 @@ function _command_exists ()
2525
_param '2: (optional) log message to include when command not found'
2626
_example '$ _command_exists ls && echo exists'
2727
_group 'lib'
28-
local msg="${2:-Command '$1' does not exist!}"
29-
type "$1" &> /dev/null || (_log_warning "$msg" && return 1) ;
28+
local msg="${2:-Command '$1' does not exist\!}"
29+
if type "$1" &> /dev/null
30+
then
31+
return "$?"
32+
else
33+
_log_debug "$msg"
34+
return 1
35+
fi
3036
}
3137

3238
function _binary_exists ()
@@ -36,8 +42,14 @@ function _binary_exists ()
3642
_param '2: (optional) log message to include when binary not found'
3743
_example '$ _binary_exists ls && echo exists'
3844
_group 'lib'
39-
local msg="${2:-Binary '$1' does not exist!}"
40-
type -P "$1" &> /dev/null || (_log_warning "$msg" && return 1) ;
45+
local msg="${2:-Binary '$1' does not exist\!}"
46+
if type -P "$1" &> /dev/null
47+
then
48+
return "$?"
49+
else
50+
_log_debug "$msg"
51+
return 1
52+
fi
4153
}
4254

4355
function _completion_exists ()

0 commit comments

Comments
 (0)