Merge 9ed8cddc8a into 2ef5d483e3
commit
9ce41040b1
|
|
@ -22,51 +22,6 @@ else
|
||||||
BASH_IT_SED_I_PARAMETERS=('-i' '')
|
BASH_IT_SED_I_PARAMETERS=('-i' '')
|
||||||
fi
|
fi
|
||||||
|
|
||||||
function _command_exists() {
|
|
||||||
_about 'checks for existence of a command'
|
|
||||||
_param '1: command to check'
|
|
||||||
_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}"
|
|
||||||
if type -t "$1" > /dev/null; then
|
|
||||||
return 0
|
|
||||||
else
|
|
||||||
_log_debug "$msg"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
function _binary_exists() {
|
|
||||||
_about 'checks for existence of a binary'
|
|
||||||
_param '1: binary to check'
|
|
||||||
_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}"
|
|
||||||
if type -P "$1" > /dev/null; then
|
|
||||||
return 0
|
|
||||||
else
|
|
||||||
_log_debug "$msg"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
function _completion_exists() {
|
|
||||||
_about 'checks for existence of a completion'
|
|
||||||
_param '1: command to check'
|
|
||||||
_param '2: (optional) log message to include when completion is found'
|
|
||||||
_example '$ _completion_exists gh && echo exists'
|
|
||||||
_group 'lib'
|
|
||||||
local msg="${2:-Completion for '$1' already exists}"
|
|
||||||
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() {
|
||||||
if _binary_exists 'brew'; then
|
if _binary_exists 'brew'; then
|
||||||
# Homebrew is installed
|
# Homebrew is installed
|
||||||
|
|
@ -203,22 +158,6 @@ function bash-it() {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function _is_function() {
|
|
||||||
_about 'sets $? to true if parameter is the name of a function'
|
|
||||||
_param '1: name of alleged function'
|
|
||||||
_param '2: (optional) log message to include when function not found'
|
|
||||||
_group 'lib'
|
|
||||||
_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
|
|
||||||
}
|
|
||||||
|
|
||||||
function _bash-it-aliases() {
|
function _bash-it-aliases() {
|
||||||
_about 'summarizes available bash_it aliases'
|
_about 'summarizes available bash_it aliases'
|
||||||
_group 'lib'
|
_group 'lib'
|
||||||
|
|
|
||||||
|
|
@ -72,6 +72,42 @@ function _bash-it-egrep() {
|
||||||
"${BASH_IT_GREP:-/usr/bin/grep}" -E "$@"
|
"${BASH_IT_GREP:-/usr/bin/grep}" -E "$@"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function _command_exists() {
|
||||||
|
: _about 'checks for existence of a command'
|
||||||
|
: _param '1: command to check'
|
||||||
|
: _example '$ _command_exists ls && echo exists'
|
||||||
|
: _group 'lib'
|
||||||
|
|
||||||
|
type -t "${1?}" > /dev/null
|
||||||
|
}
|
||||||
|
|
||||||
|
function _binary_exists() {
|
||||||
|
: _about 'checks for existence of a binary'
|
||||||
|
: _param '1: binary to check'
|
||||||
|
: _example '$ _binary_exists ls && echo exists'
|
||||||
|
: _group 'lib'
|
||||||
|
|
||||||
|
type -P "${1?}" > /dev/null
|
||||||
|
}
|
||||||
|
|
||||||
|
function _completion_exists() {
|
||||||
|
: _about 'checks for existence of a completion'
|
||||||
|
: _param '1: command to check'
|
||||||
|
: _example '$ _completion_exists gh && echo exists'
|
||||||
|
: _group 'lib'
|
||||||
|
|
||||||
|
complete -p "${1?}" &> /dev/null
|
||||||
|
}
|
||||||
|
|
||||||
|
function _is_function() {
|
||||||
|
: _about 'sets $? to true if parameter is the name of a function'
|
||||||
|
: _param '1: name of alleged function'
|
||||||
|
: _example '$ _is_function ls && echo exists'
|
||||||
|
: _group 'lib'
|
||||||
|
|
||||||
|
declare -F "${1?}" > /dev/null
|
||||||
|
}
|
||||||
|
|
||||||
###########################################################################
|
###########################################################################
|
||||||
# Component-specific functions (component is either an alias, a plugin, or a
|
# Component-specific functions (component is either an alias, a plugin, or a
|
||||||
# completion).
|
# completion).
|
||||||
|
|
@ -175,7 +211,7 @@ function _bash-it-component-item-is-enabled() {
|
||||||
component_type="${1}" item_name="${2?}"
|
component_type="${1}" item_name="${2?}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
for each_file in "${BASH_IT}/enabled"/*"${BASH_IT_LOAD_PRIORITY_SEPARATOR?}${item_name}.${component_type}"*."bash" \
|
for each_file in "${BASH_IT?}/enabled"/*"${BASH_IT_LOAD_PRIORITY_SEPARATOR?}${item_name}.${component_type}"*."bash" \
|
||||||
"${BASH_IT}/${component_type}"*/"enabled/${item_name}.${component_type}"*."bash" \
|
"${BASH_IT}/${component_type}"*/"enabled/${item_name}.${component_type}"*."bash" \
|
||||||
"${BASH_IT}/${component_type}"*/"enabled"/*"${BASH_IT_LOAD_PRIORITY_SEPARATOR?}${item_name}.${component_type}"*."bash"; do
|
"${BASH_IT}/${component_type}"*/"enabled"/*"${BASH_IT_LOAD_PRIORITY_SEPARATOR?}${item_name}.${component_type}"*."bash"; do
|
||||||
if [[ -f "${each_file}" ]]; then
|
if [[ -f "${each_file}" ]]; then
|
||||||
|
|
|
||||||
|
|
@ -20,46 +20,6 @@ function local_setup() {
|
||||||
assert_file_exist "$BASH_IT/profiles/test-bad-type.bash_it"
|
assert_file_exist "$BASH_IT/profiles/test-bad-type.bash_it"
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "helpers: _command_exists function exists" {
|
|
||||||
run type -a _command_exists &> /dev/null
|
|
||||||
assert_success
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "helpers: _command_exists function positive test ls" {
|
|
||||||
run _command_exists ls
|
|
||||||
assert_success
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "helpers: _command_exists function positive test bash-it" {
|
|
||||||
run _command_exists bash-it
|
|
||||||
assert_success
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "helpers: _command_exists function negative test" {
|
|
||||||
run _command_exists __addfkds_dfdsjdf
|
|
||||||
assert_failure
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "helpers: _binary_exists function exists" {
|
|
||||||
run type -a _binary_exists &> /dev/null
|
|
||||||
assert_success
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "helpers: _binary_exists function positive test ls" {
|
|
||||||
run _binary_exists ls
|
|
||||||
assert_success
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "helpers: _binary_exists function negative test function" {
|
|
||||||
run _binary_exists _binary_exists
|
|
||||||
assert_failure
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "helpers: _binary_exists function negative test" {
|
|
||||||
run _binary_exists __addfkds_dfdsjdf
|
|
||||||
assert_failure
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "helpers: bash-it help aliases ag" {
|
@test "helpers: bash-it help aliases ag" {
|
||||||
run bash-it help aliases "ag"
|
run bash-it help aliases "ag"
|
||||||
assert_line -n 0 "ag='ag --smart-case --pager=\"less -MIRFX'"
|
assert_line -n 0 "ag='ag --smart-case --pager=\"less -MIRFX'"
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,71 @@ function local_setup_file() {
|
||||||
setup_libs "helpers"
|
setup_libs "helpers"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@test "utilities: _is_function: _command_exists" {
|
||||||
|
run _is_function _command_exists
|
||||||
|
assert_success
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "utilities: _command_exists function positive test ls" {
|
||||||
|
run _command_exists ls
|
||||||
|
assert_success
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "utilities: _command_exists function positive test bash-it" {
|
||||||
|
run _command_exists bash-it
|
||||||
|
assert_success
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "utilities: _command_exists function negative test" {
|
||||||
|
run _command_exists "__addfkds_dfdsjdf_${RANDOM:-}"
|
||||||
|
assert_failure
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "utilities: _is_function: _binary_exists" {
|
||||||
|
run _is_function _binary_exists
|
||||||
|
assert_success
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "utilities: _binary_exists function positive test ls" {
|
||||||
|
run _binary_exists ls
|
||||||
|
assert_success
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "utilities: _binary_exists function negative test function" {
|
||||||
|
run _binary_exists _binary_exists
|
||||||
|
assert_failure
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "utilities: _binary_exists function negative test" {
|
||||||
|
run _binary_exists "__addfkds_dfdsjdf_${RANDOM:-}"
|
||||||
|
assert_failure
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "utilities: _is_function: _completion_exists" {
|
||||||
|
run _is_function _completion_exists
|
||||||
|
assert_success
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "utilities: _is_function new function" {
|
||||||
|
local teh_new_func="__addfkds_dfdsjdf_${RANDOM:-}"
|
||||||
|
run _is_function "${teh_new_func?}"
|
||||||
|
assert_failure
|
||||||
|
|
||||||
|
cite "${teh_new_func?}"
|
||||||
|
run _is_function "${teh_new_func?}"
|
||||||
|
assert_success
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "utilities: _command_exists new function" {
|
||||||
|
local teh_new_func="__addfkds_dfdsjdf_${RANDOM:-}"
|
||||||
|
run _command_exists "${teh_new_func?}"
|
||||||
|
assert_failure
|
||||||
|
|
||||||
|
cite "${teh_new_func?}"
|
||||||
|
run _command_exists "${teh_new_func?}"
|
||||||
|
assert_success
|
||||||
|
}
|
||||||
|
|
||||||
@test "_bash-it-component-item-is-enabled() - for a disabled item" {
|
@test "_bash-it-component-item-is-enabled() - for a disabled item" {
|
||||||
run _bash-it-component-item-is-enabled aliases svn
|
run _bash-it-component-item-is-enabled aliases svn
|
||||||
assert_failure
|
assert_failure
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue