Merge pull request #1973 from gaelicWizard/utilities
lib/utilities: minor improvementspull/1976/head
commit
5e3810ac96
|
|
@ -11,7 +11,7 @@ function _bash-it-get-component-name-from-path() {
|
||||||
# filename without path
|
# filename without path
|
||||||
filename="${1##*/}"
|
filename="${1##*/}"
|
||||||
# filename without path or priority
|
# filename without path or priority
|
||||||
filename="${filename##*${BASH_IT_LOAD_PRIORITY_SEPARATOR?}}"
|
filename="${filename##*"${BASH_IT_LOAD_PRIORITY_SEPARATOR?}"}"
|
||||||
# filename without path, priority or extension
|
# filename without path, priority or extension
|
||||||
echo "${filename%.*.bash}"
|
echo "${filename%.*.bash}"
|
||||||
}
|
}
|
||||||
|
|
@ -40,7 +40,7 @@ function _bash-it-get-component-type-from-path() {
|
||||||
# $ _bash-it-array-contains-element apple "@{fruits[@]}" && echo 'contains apple'
|
# $ _bash-it-array-contains-element apple "@{fruits[@]}" && echo 'contains apple'
|
||||||
# contains apple
|
# contains apple
|
||||||
#
|
#
|
||||||
# $ if $(_bash-it-array-contains-element pear "${fruits[@]}"); then
|
# $ if _bash-it-array-contains-element pear "${fruits[@]}"; then
|
||||||
# echo "contains pear!"
|
# echo "contains pear!"
|
||||||
# fi
|
# fi
|
||||||
# contains pear!
|
# contains pear!
|
||||||
|
|
@ -54,10 +54,9 @@ function _bash-it-array-contains-element() {
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
# Dedupe a simple array of words without spaces.
|
# Dedupe an array (without embedded newlines).
|
||||||
function _bash-it-array-dedup() {
|
function _bash-it-array-dedup() {
|
||||||
local IFS=$'\n'
|
printf '%s\n' "$@" | sort -u
|
||||||
echo "$@" | tr ' ' '\n' | sort -u
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Outputs a full path of the grep found on the filesystem
|
# Outputs a full path of the grep found on the filesystem
|
||||||
|
|
@ -66,6 +65,12 @@ function _bash-it-grep() {
|
||||||
printf "%s" "${BASH_IT_GREP:-'/usr/bin/grep'}"
|
printf "%s" "${BASH_IT_GREP:-'/usr/bin/grep'}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Runs `grep` with extended regular expressions
|
||||||
|
function _bash-it-egrep() {
|
||||||
|
: "${BASH_IT_GREP:=$(type -p egrep || type -p grep)}"
|
||||||
|
"${BASH_IT_GREP:-/usr/bin/grep}" -E "$@"
|
||||||
|
}
|
||||||
|
|
||||||
###########################################################################
|
###########################################################################
|
||||||
# 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).
|
||||||
|
|
@ -76,17 +81,16 @@ function _bash-it-component-help() {
|
||||||
component="$(_bash-it-pluralize-component "${1}")"
|
component="$(_bash-it-pluralize-component "${1}")"
|
||||||
file="$(_bash-it-component-cache-file "${component}")"
|
file="$(_bash-it-component-cache-file "${component}")"
|
||||||
if [[ ! -s "${file}" || -z "$(find "${file}" -mmin -300)" ]]; then
|
if [[ ! -s "${file}" || -z "$(find "${file}" -mmin -300)" ]]; then
|
||||||
rm -f "${file}" 2> /dev/null
|
|
||||||
func="_bash-it-${component}"
|
func="_bash-it-${component}"
|
||||||
"${func}" | ${BASH_IT_GREP:-$(_bash-it-grep)} -E ' \[' > "${file}"
|
"${func}" | ${BASH_IT_GREP:-$(_bash-it-grep)} -E ' \[' >| "${file}"
|
||||||
fi
|
fi
|
||||||
cat "${file}"
|
cat "${file}"
|
||||||
}
|
}
|
||||||
|
|
||||||
function _bash-it-component-cache-file() {
|
function _bash-it-component-cache-file() {
|
||||||
local component file
|
local component file
|
||||||
component="$(_bash-it-pluralize-component "${1}")"
|
component="$(_bash-it-pluralize-component "${1?${FUNCNAME[0]}: component name required}")"
|
||||||
file="${BASH_IT?}/tmp/cache/${component}"
|
file="${XDG_CACHE_HOME:-${BASH_IT?}/tmp/cache}${XDG_CACHE_HOME:+/bash_it}/${component}"
|
||||||
[[ -f "${file}" ]] || mkdir -p "${file%/*}"
|
[[ -f "${file}" ]] || mkdir -p "${file%/*}"
|
||||||
printf '%s' "${file}"
|
printf '%s' "${file}"
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue