Skip to content

Commit 0dbf1d5

Browse files
author
Noah Gorny
authored
Merge pull request #1926 from gaelicWizard/basenamed
Use parameter substitution instead of `dirname`/`basename`, where safe to do so
2 parents 1c3cbf7 + 470341b commit 0dbf1d5

7 files changed

+24
-22
lines changed

install.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ if [[ -n "${no_modify_config}" && -n "${append_to_config}" ]]; then
184184
exit 1
185185
fi
186186

187-
BASH_IT="$(cd "$(dirname "$0")" && pwd)"
187+
BASH_IT="$(cd "${BASH_SOURCE%/*}" && pwd)"
188188

189189
case $OSTYPE in
190190
darwin*)

lib/helpers.bash

+5-5
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ _bash-it-migrate() {
340340
do
341341
for f in `sort <(compgen -G "${BASH_IT}/$file_type/enabled/*.bash")`
342342
do
343-
typeset ff=$(basename $f)
343+
typeset ff="${f##*/}"
344344

345345
# Get the type of component from the extension
346346
typeset single_type=$(echo $ff | sed -e 's/.*\.\(.*\)\.bash/\1/g' | sed 's/aliases/alias/g')
@@ -501,7 +501,7 @@ _bash-it-describe ()
501501
do
502502
# Check for both the old format without the load priority, and the extended format with the priority
503503
declare enabled_files enabled_file
504-
enabled_file=$(basename $f)
504+
enabled_file="${f##*/}"
505505
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)
506506

507507
if [ $enabled_files -gt 0 ]; then
@@ -603,9 +603,9 @@ _disable-thing ()
603603
printf '%s\n' "sorry, $file_entity does not appear to be an enabled $file_type."
604604
return
605605
fi
606-
rm "${BASH_IT}/$subdirectory/enabled/$(basename $plugin)"
606+
rm "${BASH_IT}/$subdirectory/enabled/${plugin##*/}"
607607
else
608-
rm "${BASH_IT}/enabled/$(basename $plugin_global)"
608+
rm "${BASH_IT}/enabled/${plugin_global##*/}"
609609
fi
610610
fi
611611

@@ -681,7 +681,7 @@ _enable-thing ()
681681
return
682682
fi
683683

684-
to_enable=$(basename $to_enable)
684+
to_enable="${to_enable##*/}"
685685
# Check for existence of the file using a wildcard, since we don't know which priority might have been used when enabling it.
686686
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)
687687
if [ ! -z "$enabled_plugin" ] ; then

lib/utilities.bash

+4-4
Original file line numberDiff line numberDiff line change
@@ -71,20 +71,20 @@ _bash-it-grep() {
7171
###########################################################################
7272

7373
_bash-it-component-help() {
74-
local component=$(_bash-it-pluralize-component "${1}")
75-
local file=$(_bash-it-component-cache-file ${component})
74+
local component="$(_bash-it-pluralize-component "${1}")"
75+
local file="$(_bash-it-component-cache-file "${component}")"
7676
if [[ ! -s "${file}" || -z $(find "${file}" -mmin -300) ]] ; then
7777
rm -f "${file}" 2>/dev/null
7878
local func="_bash-it-${component}"
79-
${func} | $(_bash-it-grep) -E ' \[' | cat > ${file}
79+
"${func}" | $(_bash-it-grep) -E ' \[' | cat > "${file}"
8080
fi
8181
cat "${file}"
8282
}
8383

8484
_bash-it-component-cache-file() {
8585
local component=$(_bash-it-pluralize-component "${1}")
8686
local file="${BASH_IT}/tmp/cache/${component}"
87-
[[ -f ${file} ]] || mkdir -p $(dirname ${file})
87+
[[ -f "${file}" ]] || mkdir -p "${file%/*}"
8888
printf "${file}"
8989
}
9090

plugins/available/jekyll.plugin.bash

+5-5
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ editpost() {
1616

1717
for site in ${SITES[@]}
1818
do
19-
if [ "$(basename $site)" = "$1" ]
19+
if [ "${site##*/}" = "$1" ]
2020
then
2121
SITE=$site
2222
break
@@ -77,7 +77,7 @@ newpost() {
7777

7878
for site in ${SITES[@]}
7979
do
80-
if [ "$(basename $site)" = "$1" ]
80+
if [ "${site##*/}" = "$1" ]
8181
then
8282
SITE=$site
8383
JEKYLL_FORMATTING=${MARKUPS[$loc]}
@@ -280,7 +280,7 @@ function testsite() {
280280

281281
for site in ${SITES[@]}
282282
do
283-
if [ "$(basename $site)" = "$1" ]
283+
if [ "${site##*/}" = "$1" ]
284284
then
285285
SITE=$site
286286
break
@@ -312,7 +312,7 @@ function buildsite() {
312312

313313
for site in ${SITES[@]}
314314
do
315-
if [ "$(basename $site)" = "$1" ]
315+
if [ "${site##*/}" = "$1" ]
316316
then
317317
SITE=$site
318318
break
@@ -347,7 +347,7 @@ function deploysite() {
347347

348348
for site in ${SITES[@]}
349349
do
350-
if [ "$(basename $site)" = "$1" ]
350+
if [ "${site##*/}" = "$1" ]
351351
then
352352
SITE=$site
353353
REMOTE=${REMOTES[$loc]}

plugins/available/osx-timemachine.plugin.bash

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ function time-machine-list-machines() {
1515
local tmdest="$(time-machine-destination)/Backups.backupdb"
1616

1717
find "$tmdest" -maxdepth 1 -mindepth 1 -type d | grep -v "/\." | while read line ; do
18-
echo "$(basename "$line")"
18+
echo "${line##*/}"
1919
done
2020
}
2121

plugins/available/virtualenv.plugin.bash

+7-5
Original file line numberDiff line numberDiff line change
@@ -14,28 +14,30 @@ function mkvenv {
1414
about 'create a new virtualenv for this directory'
1515
group 'virtualenv'
1616

17-
cwd=`basename \`pwd\``
18-
mkvirtualenv --distribute $cwd
17+
local cwd="${PWD##*/}"
18+
mkvirtualenv --distribute "$cwd"
1919
}
2020

2121

2222
function mkvbranch {
2323
about 'create a new virtualenv for the current branch'
2424
group 'virtualenv'
2525

26-
mkvirtualenv --distribute "$(basename `pwd`)@$SCM_BRANCH"
26+
local cwd="${PWD##*/}"
27+
mkvirtualenv --distribute "${cwd}@${SCM_BRANCH}"
2728
}
2829

2930
function wovbranch {
3031
about 'sets workon branch'
3132
group 'virtualenv'
3233

33-
workon "$(basename `pwd`)@$SCM_BRANCH"
34+
local cwd="${PWD##*/}"
35+
workon "${cwd}@${SCM_BRANCH}"
3436
}
3537

3638
function wovenv {
3739
about 'works on the virtualenv for this directory'
3840
group 'virtualenv'
3941

40-
workon "$(basename `pwd`)"
42+
workon "${PWD##*/}"
4143
}

plugins/available/z_autoenv.plugin.bash

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ autoenv_init()
1111
typeset target home _file
1212
typeset -a _files
1313
target=$1
14-
home="$(dirname "$HOME")"
14+
home="${HOME%/*}"
1515

1616
_files=( $(
1717
while [[ "$PWD" != "/" && "$PWD" != "$home" ]]

0 commit comments

Comments
 (0)