pull/1473/head
cornfeedhobo 2020-01-03 21:46:53 -08:00
parent cfa94e70fa
commit 4815ef8550
No known key found for this signature in database
GPG Key ID: 724357093F994B26
1 changed files with 45 additions and 45 deletions

View File

@ -50,51 +50,6 @@ _bash-it-clean-component-cache() {
fi
}
###########################################################################
# Generic utilies
###########################################################################
# This function searches an array for an exact match against the term passed
# as the first argument to the function. This function exits as soon as
# a match is found.
#
# Returns:
# 0 when a match is found, otherwise 1.
#
# Examples:
# $ declare -a fruits=(apple orange pear mandarin)
#
# $ _bash-it-array-contains-element apple "@{fruits[@]}" && echo 'contains apple'
# contains apple
#
# $ if $(_bash-it-array-contains-element pear "${fruits[@]}"); then
# echo "contains pear!"
# fi
# contains pear!
#
#
_bash-it-array-contains-element() {
local e
for e in "${@:2}"; do
[[ "$e" == "$1" ]] && return 0
done
return 1
}
# Dedupe a simple array of words without spaces.
_bash-it-array-dedup() {
echo "$*" | tr ' ' '\n' | sort -u | tr '\n' ' '
}
# Outputs a full path of the grep found on the filesystem
_bash-it-grep() {
if [[ -z "${BASH_IT_GREP}" ]] ; then
export BASH_IT_GREP="$(which egrep || which grep || '/usr/bin/grep')"
fi
printf "%s " "${BASH_IT_GREP}"
}
# Returns an array of items within each compoenent.
_bash-it-component-list() {
local component="$1"
@ -144,3 +99,48 @@ _bash-it-component-item-is-disabled() {
local item="$2"
_bash-it-component-help "${component}" | $(_bash-it-grep) -E -v '\[x\]' | $(_bash-it-grep) -E -q -- "^${item}\s"
}
###########################################################################
# Generic utilies
###########################################################################
# This function searches an array for an exact match against the term passed
# as the first argument to the function. This function exits as soon as
# a match is found.
#
# Returns:
# 0 when a match is found, otherwise 1.
#
# Examples:
# $ declare -a fruits=(apple orange pear mandarin)
#
# $ _bash-it-array-contains-element apple "@{fruits[@]}" && echo 'contains apple'
# contains apple
#
# $ if $(_bash-it-array-contains-element pear "${fruits[@]}"); then
# echo "contains pear!"
# fi
# contains pear!
#
#
_bash-it-array-contains-element() {
local e
for e in "${@:2}"; do
[[ "$e" == "$1" ]] && return 0
done
return 1
}
# Dedupe a simple array of words without spaces.
_bash-it-array-dedup() {
echo "$*" | tr ' ' '\n' | sort -u | tr '\n' ' '
}
# Outputs a full path of the grep found on the filesystem
_bash-it-grep() {
if [[ -z "${BASH_IT_GREP}" ]] ; then
export BASH_IT_GREP="$(which egrep || which grep || '/usr/bin/grep')"
fi
printf "%s " "${BASH_IT_GREP}"
}