Skip to content

Commit

Permalink
lib/helpers: simplify _command_exists() and _binary_exists()
Browse files Browse the repository at this point in the history
Remove subshell and just use a regular `if`
  • Loading branch information
gaelicWizard committed Sep 19, 2021
1 parent 0d75859 commit e73b9f0
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions lib/helpers.bash
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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 ()
Expand All @@ -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 ()
Expand Down

0 comments on commit e73b9f0

Please sign in to comment.