Merge pull request #1926 from gaelicWizard/basenamed

Use parameter substitution instead of `dirname`/`basename`, where safe to do so
This commit is contained in:
Noah Gorny
2021-09-18 18:26:55 +03:00
committed by GitHub
7 changed files with 24 additions and 22 deletions

View File

@@ -340,7 +340,7 @@ _bash-it-migrate() {
do
for f in `sort <(compgen -G "${BASH_IT}/$file_type/enabled/*.bash")`
do
typeset ff=$(basename $f)
typeset ff="${f##*/}"
# Get the type of component from the extension
typeset single_type=$(echo $ff | sed -e 's/.*\.\(.*\)\.bash/\1/g' | sed 's/aliases/alias/g')
@@ -501,7 +501,7 @@ _bash-it-describe ()
do
# Check for both the old format without the load priority, and the extended format with the priority
declare enabled_files enabled_file
enabled_file=$(basename $f)
enabled_file="${f##*/}"
enabled_files=$(sort <(compgen -G "${BASH_IT}/enabled/*$BASH_IT_LOAD_PRIORITY_SEPARATOR${enabled_file}") <(compgen -G "${BASH_IT}/$subdirectory/enabled/${enabled_file}") <(compgen -G "${BASH_IT}/$subdirectory/enabled/*$BASH_IT_LOAD_PRIORITY_SEPARATOR${enabled_file}") | wc -l)
if [ $enabled_files -gt 0 ]; then
@@ -603,9 +603,9 @@ _disable-thing ()
printf '%s\n' "sorry, $file_entity does not appear to be an enabled $file_type."
return
fi
rm "${BASH_IT}/$subdirectory/enabled/$(basename $plugin)"
rm "${BASH_IT}/$subdirectory/enabled/${plugin##*/}"
else
rm "${BASH_IT}/enabled/$(basename $plugin_global)"
rm "${BASH_IT}/enabled/${plugin_global##*/}"
fi
fi
@@ -681,7 +681,7 @@ _enable-thing ()
return
fi
to_enable=$(basename $to_enable)
to_enable="${to_enable##*/}"
# Check for existence of the file using a wildcard, since we don't know which priority might have been used when enabling it.
typeset enabled_plugin=$(command ls "${BASH_IT}/$subdirectory/enabled/"{[0-9][0-9][0-9]$BASH_IT_LOAD_PRIORITY_SEPARATOR$to_enable,$to_enable} 2>/dev/null | head -1)
if [ ! -z "$enabled_plugin" ] ; then

View File

@@ -71,12 +71,12 @@ _bash-it-grep() {
###########################################################################
_bash-it-component-help() {
local component=$(_bash-it-pluralize-component "${1}")
local file=$(_bash-it-component-cache-file ${component})
local component="$(_bash-it-pluralize-component "${1}")"
local file="$(_bash-it-component-cache-file "${component}")"
if [[ ! -s "${file}" || -z $(find "${file}" -mmin -300) ]] ; then
rm -f "${file}" 2>/dev/null
local func="_bash-it-${component}"
${func} | $(_bash-it-grep) -E ' \[' | cat > ${file}
"${func}" | $(_bash-it-grep) -E ' \[' | cat > "${file}"
fi
cat "${file}"
}
@@ -84,7 +84,7 @@ _bash-it-component-help() {
_bash-it-component-cache-file() {
local component=$(_bash-it-pluralize-component "${1}")
local file="${BASH_IT}/tmp/cache/${component}"
[[ -f ${file} ]] || mkdir -p $(dirname ${file})
[[ -f "${file}" ]] || mkdir -p "${file%/*}"
printf "${file}"
}