Merge pull request #2018 from gaelicWizard/lib/helpers-base
lib/helpers: fix `_command_exists()`pull/2034/head
commit
4ba1ab9fd7
|
|
@ -15,49 +15,49 @@ case "$OSTYPE" in
|
||||||
'darwin'*) BASH_IT_SED_I_PARAMETERS=(-i "")
|
'darwin'*) BASH_IT_SED_I_PARAMETERS=(-i "")
|
||||||
esac
|
esac
|
||||||
|
|
||||||
function _command_exists ()
|
function _command_exists() {
|
||||||
{
|
|
||||||
_about 'checks for existence of a command'
|
_about 'checks for existence of a command'
|
||||||
_param '1: command to check'
|
_param '1: command to check'
|
||||||
_param '2: (optional) log message to include when command not found'
|
_param '2: (optional) log message to include when command not found'
|
||||||
_example '$ _command_exists ls && echo exists'
|
_example '$ _command_exists ls && echo exists'
|
||||||
_group 'lib'
|
_group 'lib'
|
||||||
local msg="${2:-Command '$1' does not exist!}"
|
local msg="${2:-Command '$1' does not exist}"
|
||||||
if type -t "$1" &> /dev/null
|
if type -t "$1" > /dev/null; then
|
||||||
then
|
|
||||||
return 0
|
return 0
|
||||||
else
|
else
|
||||||
_log_warning "$msg"
|
_log_debug "$msg"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function _binary_exists ()
|
function _binary_exists() {
|
||||||
{
|
|
||||||
_about 'checks for existence of a binary'
|
_about 'checks for existence of a binary'
|
||||||
_param '1: binary to check'
|
_param '1: binary to check'
|
||||||
_param '2: (optional) log message to include when binary not found'
|
_param '2: (optional) log message to include when binary not found'
|
||||||
_example '$ _binary_exists ls && echo exists'
|
_example '$ _binary_exists ls && echo exists'
|
||||||
_group 'lib'
|
_group 'lib'
|
||||||
local msg="${2:-Binary '$1' does not exist!}"
|
local msg="${2:-Binary '$1' does not exist}"
|
||||||
if type -P "$1" &> /dev/null
|
if type -P "$1" > /dev/null; then
|
||||||
then
|
|
||||||
return 0
|
return 0
|
||||||
else
|
else
|
||||||
_log_warning "$msg"
|
_log_debug "$msg"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function _completion_exists ()
|
function _completion_exists() {
|
||||||
{
|
|
||||||
_about 'checks for existence of a completion'
|
_about 'checks for existence of a completion'
|
||||||
_param '1: command to check'
|
_param '1: command to check'
|
||||||
_param '2: (optional) log message to include when completion is found'
|
_param '2: (optional) log message to include when completion is found'
|
||||||
_example '$ _completion_exists gh && echo exists'
|
_example '$ _completion_exists gh && echo exists'
|
||||||
_group 'lib'
|
_group 'lib'
|
||||||
local msg="${2:-Completion for '$1' already exists!}"
|
local msg="${2:-Completion for '$1' already exists}"
|
||||||
complete -p "$1" &> /dev/null && _log_warning "$msg" ;
|
if complete -p "$1" &> /dev/null; then
|
||||||
|
_log_debug "$msg"
|
||||||
|
return 0
|
||||||
|
else
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function _bash_it_homebrew_check()
|
function _bash_it_homebrew_check()
|
||||||
|
|
@ -179,12 +179,20 @@ bash-it ()
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
_is_function ()
|
function _is_function() {
|
||||||
{
|
|
||||||
_about 'sets $? to true if parameter is the name of a function'
|
_about 'sets $? to true if parameter is the name of a function'
|
||||||
_param '1: name of alleged function'
|
_param '1: name of alleged function'
|
||||||
|
_param '2: (optional) log message to include when function not found'
|
||||||
_group 'lib'
|
_group 'lib'
|
||||||
[ -n "$(LANG=C type -t $1 2>/dev/null | grep 'function')" ]
|
_example '$ _is_function ls && echo exists'
|
||||||
|
_group 'lib'
|
||||||
|
local msg="${2:-Function '$1' does not exist}"
|
||||||
|
if LC_ALL=C type -t "$1" | _bash-it-egrep -q 'function'; then
|
||||||
|
return 0
|
||||||
|
else
|
||||||
|
_log_debug "$msg"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
_bash-it-aliases ()
|
_bash-it-aliases ()
|
||||||
|
|
@ -1039,14 +1047,7 @@ all_groups ()
|
||||||
about 'displays all unique metadata groups'
|
about 'displays all unique metadata groups'
|
||||||
group 'lib'
|
group 'lib'
|
||||||
|
|
||||||
typeset func
|
declare -f | metafor group | sort -u
|
||||||
typeset file=$(mktemp -t composure.XXXX)
|
|
||||||
for func in $(_typeset_functions)
|
|
||||||
do
|
|
||||||
typeset -f $func | metafor group >> $file
|
|
||||||
done
|
|
||||||
cat $file | sort | uniq
|
|
||||||
rm $file
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ! type pathmunge > /dev/null 2>&1
|
if ! type pathmunge > /dev/null 2>&1
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue