From 0d9a0987d939f78349b9707f11544a7be75f369b Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Mon, 29 May 2017 07:47:17 +0200 Subject: [PATCH] Fixed missing quotes around $BASH_IT variable This should fix most issues where Bash-it is installed in a directory containing spaces. --- aliases/available/general.aliases.bash | 2 +- completion/available/bash-it.completion.bash | 8 ++--- lib/helpers.bash | 38 ++++++++++---------- lib/preview.bash | 2 +- 4 files changed, 25 insertions(+), 25 deletions(-) diff --git a/aliases/available/general.aliases.bash b/aliases/available/general.aliases.bash index a4cf4ee2..7f3dbd4d 100644 --- a/aliases/available/general.aliases.bash +++ b/aliases/available/general.aliases.bash @@ -21,7 +21,7 @@ alias _="sudo" # colored grep # Need to check an existing file for a pattern that will be found to ensure # that the check works when on an OS that supports the color option -if grep --color=auto "a" $BASH_IT/*.md &> /dev/null +if grep --color=auto "a" "${BASH_IT}/"*.md &> /dev/null then alias grep='grep --color=auto' export GREP_COLOR='1;33' diff --git a/completion/available/bash-it.completion.bash b/completion/available/bash-it.completion.bash index 6bcd179b..4d28723d 100644 --- a/completion/available/bash-it.completion.bash +++ b/completion/available/bash-it.completion.bash @@ -10,9 +10,9 @@ _bash-it-comp-list-available-not-enabled() { subdirectory="$1" - local available_things=$(for f in `ls -1 $BASH_IT/$subdirectory/available/*.bash`; + local available_things=$(for f in `ls -1 "${BASH_IT}/$subdirectory/available/"*.bash`; do - if [ ! -e $BASH_IT/$subdirectory/enabled/$(basename $f) ] && [ ! -e $BASH_IT/$subdirectory/enabled/*$BASH_IT_LOAD_PRIORITY_SEPARATOR$(basename $f) ] + if [ ! -e "${BASH_IT}/$subdirectory/enabled/"$(basename $f) ] && [ ! -e "${BASH_IT}/$subdirectory/enabled/"*$BASH_IT_LOAD_PRIORITY_SEPARATOR$(basename $f) ] then basename $f | cut -d'.' -f1 fi @@ -25,7 +25,7 @@ _bash-it-comp-list-enabled() { subdirectory="$1" - local enabled_things=$(for f in `ls -1 $BASH_IT/$subdirectory/enabled/*.bash`; + local enabled_things=$(for f in `ls -1 "${BASH_IT}/$subdirectory/enabled/"*.bash`; do basename $f | cut -d'.' -f1 | sed -e "s/^[0-9]*---//g" done) @@ -37,7 +37,7 @@ _bash-it-comp-list-available() { subdirectory="$1" - local enabled_things=$(for f in `ls -1 $BASH_IT/$subdirectory/available/*.bash`; + local enabled_things=$(for f in `ls -1 "${BASH_IT}/$subdirectory/available/"*.bash`; do basename $f | cut -d'.' -f1 done) diff --git a/lib/helpers.bash b/lib/helpers.bash index bb53513f..138d8392 100644 --- a/lib/helpers.bash +++ b/lib/helpers.bash @@ -163,7 +163,7 @@ _bash-it-migrate() { for file_type in "aliases" "plugins" "completion" do shopt -s nullglob - for f in $BASH_IT/$file_type/enabled/*.bash + for f in "${BASH_IT}/$file_type/enabled/"*.bash do typeset ff=$(basename $f) @@ -203,10 +203,10 @@ _bash-it-describe () typeset f typeset enabled printf "%-20s%-10s%s\n" "$column_header" 'Enabled?' 'Description' - for f in $BASH_IT/$subdirectory/available/*.bash + for f in "${BASH_IT}/$subdirectory/available/"*.bash do # Check for both the old format without the load priority, and the extended format with the priority - if [ -e $BASH_IT/$subdirectory/enabled/$(basename $f) ] || [ -e $BASH_IT/$subdirectory/enabled/*$BASH_IT_LOAD_PRIORITY_SEPARATOR$(basename $f) ]; then + if [ -e "${BASH_IT}/$subdirectory/enabled/"$(basename $f) ] || [ -e "${BASH_IT}/$subdirectory/enabled/"*$BASH_IT_LOAD_PRIORITY_SEPARATOR$(basename $f) ]; then enabled='x' else enabled=' ' @@ -268,14 +268,14 @@ _disable-thing () if [ "$file_entity" = "all" ]; then typeset f $file_type - for f in $BASH_IT/$subdirectory/available/*.bash + for f in "${BASH_IT}/$subdirectory/available/"*.bash do plugin=$(basename $f) - if [ -e $BASH_IT/$subdirectory/enabled/$plugin ]; then - rm $BASH_IT/$subdirectory/enabled/$(basename $plugin) + if [ -e "${BASH_IT}/$subdirectory/enabled/$plugin" ]; then + rm "${BASH_IT}/$subdirectory/enabled/$(basename $plugin)" fi - if [ -e $BASH_IT/$subdirectory/enabled/*$BASH_IT_LOAD_PRIORITY_SEPARATOR$plugin ]; then - rm $BASH_IT/$subdirectory/enabled/*$BASH_IT_LOAD_PRIORITY_SEPARATOR$(basename $plugin) + if [ -e "${BASH_IT}/$subdirectory/enabled/"*$BASH_IT_LOAD_PRIORITY_SEPARATOR$plugin ]; then + rm "${BASH_IT}/$subdirectory/enabled/"*$BASH_IT_LOAD_PRIORITY_SEPARATOR$(basename $plugin) fi done else @@ -283,12 +283,12 @@ _disable-thing () # 250---node.plugin.bash # node.plugin.bash # Either one will be matched by this glob - typeset plugin=$(command ls $BASH_IT/$subdirectory/enabled/{[0-9]*$BASH_IT_LOAD_PRIORITY_SEPARATOR$file_entity.*bash,$file_entity.*bash} 2>/dev/null | head -1) + typeset plugin=$(command ls $ "${BASH_IT}/$subdirectory/enabled/"{[0-9]*$BASH_IT_LOAD_PRIORITY_SEPARATOR$file_entity.*bash,$file_entity.*bash} 2>/dev/null | head -1) if [ -z "$plugin" ]; then 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/$(basename $plugin)" fi if [ -n "$BASH_IT_AUTOMATIC_RELOAD_AFTER_CONFIG_CHANGE" ]; then @@ -350,13 +350,13 @@ _enable-thing () if [ "$file_entity" = "all" ]; then typeset f $file_type - for f in $BASH_IT/$subdirectory/available/*.bash + for f in "${BASH_IT}/$subdirectory/available/"*.bash do to_enable=$(basename $f .$file_type.bash) _enable-thing $subdirectory $file_type $to_enable $load_priority done else - typeset to_enable=$(command ls $BASH_IT/$subdirectory/available/$file_entity.*bash 2>/dev/null | head -1) + typeset to_enable=$(command ls "${BASH_IT}/$subdirectory/available/"$file_entity.*bash 2>/dev/null | head -1) if [ -z "$to_enable" ]; then printf '%s\n' "sorry, $file_entity does not appear to be an available $file_type." return @@ -364,19 +364,19 @@ _enable-thing () to_enable=$(basename $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]*$BASH_IT_LOAD_PRIORITY_SEPARATOR$to_enable,$to_enable} 2>/dev/null | head -1) + typeset enabled_plugin=$(command ls "${BASH_IT}/$subdirectory/enabled/"{[0-9]*$BASH_IT_LOAD_PRIORITY_SEPARATOR$to_enable,$to_enable} 2>/dev/null | head -1) if [ ! -z "$enabled_plugin" ] ; then printf '%s\n' "$file_entity is already enabled." return fi - mkdir -p $BASH_IT/$subdirectory/enabled + mkdir -p "${BASH_IT}/$subdirectory/enabled" # Load the priority from the file if it present there - local local_file_priority=$(grep -E "^# BASH_IT_LOAD_PRIORITY:" $BASH_IT/$subdirectory/available/$to_enable | awk -F': ' '{ print $2 }') + local local_file_priority=$(grep -E "^# BASH_IT_LOAD_PRIORITY:" "${BASH_IT}/$subdirectory/available/$to_enable" | awk -F': ' '{ print $2 }') local use_load_priority=${local_file_priority:-$load_priority} - ln -s ../available/$to_enable $BASH_IT/$subdirectory/enabled/$use_load_priority$BASH_IT_LOAD_PRIORITY_SEPARATOR$to_enable + ln -s ../available/$to_enable "${BASH_IT}/$subdirectory/enabled/${use_load_priority}${BASH_IT_LOAD_PRIORITY_SEPARATOR}${to_enable}" fi if [ -n "$BASH_IT_AUTOMATIC_RELOAD_AFTER_CONFIG_CHANGE" ]; then @@ -410,14 +410,14 @@ _help-aliases() alias_path="available/$1.aliases.bash" ;; esac - cat $BASH_IT/aliases/$alias_path | metafor alias | sed "s/$/'/" + cat "${BASH_IT}/aliases/$alias_path" | metafor alias | sed "s/$/'/" else typeset f - for f in $BASH_IT/aliases/enabled/* + for f in "${BASH_IT}/aliases/enabled/"* do _help-list-aliases $f done - _help-list-aliases $BASH_IT/aliases/custom.aliases.bash + _help-list-aliases "${BASH_IT}/aliases/custom.aliases.bash" fi } diff --git a/lib/preview.bash b/lib/preview.bash index 306b475a..d0fb0623 100644 --- a/lib/preview.bash +++ b/lib/preview.bash @@ -14,6 +14,6 @@ then BASH_IT_THEME=${BASH_IT_THEME##*/} echo " $BASH_IT_THEME" - echo "" | bash --init-file $BASH_IT/bash_it.sh -i + echo "" | bash --init-file "${BASH_IT}/bash_it.sh" -i done fi