Skip to content

Commit

Permalink
lib/helpers: _command_exists()
Browse files Browse the repository at this point in the history
The weird subshell is weird AF. Just do a normal `if`.

Ditto `_binary_exists()`.
  • Loading branch information
gaelicWizard committed Sep 9, 2021
1 parent a4f40ad commit a40ce04
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions lib/helpers.bash
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,14 @@ function _command_exists ()
_param '2: (optional) log message to include when command not found'
_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) ;
local msg="${2:-Command '$1' does not exist\!}"
if type "$1" &> /dev/null
then
return "$?"
else
_log_debug "$msg"
return 1
fi
}

function _binary_exists ()
Expand All @@ -36,8 +42,14 @@ function _binary_exists ()
_param '2: (optional) log message to include when binary not found'
_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) ;
local msg="${2:-Binary '$1' does not exist\!}"
if type -P "$1" &> /dev/null
then
return "$?"
else
_log_debug "$msg"
return 1
fi
}

function _completion_exists ()
Expand Down

0 comments on commit a40ce04

Please sign in to comment.