Merge pull request #1511 from cornfeedhobo/nit-pick-utilities-order

Nit pick ordering
pull/1512/head
Nils Winkler 2020-03-09 09:04:55 +01:00 committed by GitHub
commit c1ec06c9d8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 45 additions and 45 deletions

View File

@ -2,6 +2,51 @@
# #
# A collection of reusable functions. # A collection of reusable functions.
###########################################################################
# 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}"
}
########################################################################### ###########################################################################
# 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).
@ -50,51 +95,6 @@ _bash-it-clean-component-cache() {
fi 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. # Returns an array of items within each compoenent.
_bash-it-component-list() { _bash-it-component-list() {
local component="$1" local component="$1"