lib/utilities: shellcheck

SC2059
pull/1933/head
John D Pell 2021-09-17 12:58:10 -07:00
parent d6c4c0cc88
commit 44ddd3936d
1 changed files with 19 additions and 18 deletions

View File

@ -1,4 +1,4 @@
#!/usr/bin/env bash # shellcheck shell=bash
# #
# A collection of reusable functions. # A collection of reusable functions.
@ -8,20 +8,21 @@
_bash-it-get-component-name-from-path() { _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##*---} filename="${filename##*---}"
# filename without path, priority or extension # filename without path, priority or extension
echo ${filename%.*.bash} echo "${filename%.*.bash}"
} }
_bash-it-get-component-type-from-path() { _bash-it-get-component-type-from-path() {
# filename without path # filename without path
filename=${1##*/} filename="${1##*/}"
# filename without path or priority # filename without extension
filename=${filename##*---} filename="${filename%.bash}"
# extension # extension without priority or name
echo ${filename} | cut -d '.' -f 2 #filename="${filename#*.}"
echo "${filename#*.}" #| cut -d '.' -f 2
} }
# This function searches an array for an exact match against the term passed # This function searches an array for an exact match against the term passed
@ -73,7 +74,7 @@ _bash-it-grep() {
_bash-it-component-help() { _bash-it-component-help() {
local component="$(_bash-it-pluralize-component "${1}")" local component="$(_bash-it-pluralize-component "${1}")"
local file="$(_bash-it-component-cache-file "${component}")" local 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 rm -f "${file}" 2>/dev/null
local func="_bash-it-${component}" local func="_bash-it-${component}"
"${func}" | $(_bash-it-grep) -E ' \[' | cat > "${file}" "${func}" | $(_bash-it-grep) -E ' \[' | cat > "${file}"
@ -82,31 +83,31 @@ _bash-it-component-help() {
} }
_bash-it-component-cache-file() { _bash-it-component-cache-file() {
local component=$(_bash-it-pluralize-component "${1}") local component="$(_bash-it-pluralize-component "${1}")"
local file="${BASH_IT}/tmp/cache/${component}" local file="${BASH_IT}/tmp/cache/${component}"
[[ -f "${file}" ]] || mkdir -p "${file%/*}" [[ -f "${file}" ]] || mkdir -p "${file%/*}"
printf "${file}" printf '%s' "${file}"
} }
_bash-it-pluralize-component() { _bash-it-pluralize-component() {
local component="${1}" local component="${1}"
local len=$(( ${#component} - 1 )) local -i len=$(( ${#component} - 1 ))
# pluralize component name for consistency # pluralize component name for consistency
[[ ${component:${len}:1} != 's' ]] && component="${component}s" [[ "${component:${len}:1}" != 's' ]] && component="${component}s"
[[ ${component} == "alias" ]] && component="aliases" [[ "${component}" == "alias" ]] && component="aliases"
printf ${component} printf '%s' "${component}"
} }
_bash-it-clean-component-cache() { _bash-it-clean-component-cache() {
local component="$1" local component="$1"
local cache local cache
local -a BASH_IT_COMPONENTS=(aliases plugins completions) local -a BASH_IT_COMPONENTS=(aliases plugins completions)
if [[ -z ${component} ]] ; then if [[ -z "${component}" ]] ; then
for component in "${BASH_IT_COMPONENTS[@]}" ; do for component in "${BASH_IT_COMPONENTS[@]}" ; do
_bash-it-clean-component-cache "${component}" _bash-it-clean-component-cache "${component}"
done done
else else
cache="$(_bash-it-component-cache-file ${component})" cache="$(_bash-it-component-cache-file "${component}")"
if [[ -f "${cache}" ]] ; then if [[ -f "${cache}" ]] ; then
rm -f "${cache}" rm -f "${cache}"
fi fi