From c41bc37281bfb7275fc9c4359ccea8cb8848b82d Mon Sep 17 00:00:00 2001 From: John D Pell Date: Sun, 5 Sep 2021 16:15:02 -0700 Subject: [PATCH] drop `dirname` in favor of native Bash strings (1 of 2) Convert `var=${dirname $filename)` to `var="${filename%/*}` in cases where there is no ambiguity. Make sure that the path in `$BASH_IT` is absolute because this path gets embedded in the template `.bash_profile` file if selected by the user. --- install.sh | 2 +- lib/utilities.bash | 6 +++--- plugins/available/z_autoenv.plugin.bash | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/install.sh b/install.sh index 4940360f..13721fd2 100755 --- a/install.sh +++ b/install.sh @@ -184,7 +184,7 @@ if [[ $no_modify_config ]] && [[ $append_to_config ]]; then exit 1 fi -BASH_IT="$(cd "$(dirname "$0")" && pwd)" +BASH_IT="$(cd "${BASH_SOURCE%/*}" && pwd)" case $OSTYPE in darwin*) diff --git a/lib/utilities.bash b/lib/utilities.bash index b6322a1d..d8b4ad74 100755 --- a/lib/utilities.bash +++ b/lib/utilities.bash @@ -72,11 +72,11 @@ _bash-it-grep() { _bash-it-component-help() { 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 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}" } diff --git a/plugins/available/z_autoenv.plugin.bash b/plugins/available/z_autoenv.plugin.bash index 553a7ba3..a2f97d28 100644 --- a/plugins/available/z_autoenv.plugin.bash +++ b/plugins/available/z_autoenv.plugin.bash @@ -11,7 +11,7 @@ autoenv_init() typeset target home _file typeset -a _files target=$1 - home="$(dirname "$HOME")" + home="${HOME%/*}" _files=( $( while [[ "$PWD" != "/" && "$PWD" != "$home" ]]