From 4815ef855025f5ca3bdcd77e3ac531a708b33e71 Mon Sep 17 00:00:00 2001 From: cornfeedhobo Date: Fri, 3 Jan 2020 21:46:53 -0800 Subject: [PATCH] organize --- lib/utilities.bash | 90 +++++++++++++++++++++++----------------------- 1 file changed, 45 insertions(+), 45 deletions(-) diff --git a/lib/utilities.bash b/lib/utilities.bash index dbefbc27..1a7661b2 100644 --- a/lib/utilities.bash +++ b/lib/utilities.bash @@ -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}" +}