Skip to content

Commit

Permalink
Fix for sorted compgen glob
Browse files Browse the repository at this point in the history
In order to properly deal with doing an alphabetical sort of lines, set $IFS before parsing the result. Store the result to an array and, after restoring $IFS to it’s previous value, then iterate the already-sorted array.

Alsö, quote the path when sourced.
  • Loading branch information
gaelicWizard committed Sep 6, 2021
1 parent accfcba commit d10a278
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions scripts/reloader.bash
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,30 @@ if [[ "$1" != "skip" ]] && [[ -d "$BASH_IT/enabled" ]]; then
_log_debug "Loading all enabled components..." ;;
esac

for _bash_it_config_file in $(sort <(compgen -G "$BASH_IT/enabled/*${_bash_it_config_type}.bash")); do
OLDIFS="$IFS"; IFS=$'\n'
_bash_it_config_files=( $(sort <(compgen -G "$BASH_IT/enabled/*${_bash_it_config_type}.bash")) )
IFS="$OLDIFS"; unset OLDIFS
for _bash_it_config_file in "${_bash_it_config_files[@]}"; do
if [ -e "${_bash_it_config_file}" ]; then
_set-prefix-based-on-path "${_bash_it_config_file}"
_log_debug "Loading component..."
# shellcheck source=/dev/null
source $_bash_it_config_file
source "$_bash_it_config_file"
else
echo "Unable to read ${_bash_it_config_file}" > /dev/stderr
fi
done
unset _bash_it_config_files
fi

if [[ -n "${2}" ]] && [[ -d "$BASH_IT/${2}/enabled" ]]; then
case $2 in
aliases|completion|plugins)
_log_warning "Using legacy enabling for $2, please update your bash-it version and migrate"
for _bash_it_config_file in $(sort <(compgen -G "$BASH_IT/${2}/enabled/*.bash")); do
OLDIFS="$IFS"; IFS=$'\n'
_bash_it_config_files=( $(sort <(compgen -G "$BASH_IT/${2}/enabled/*.bash")) )
IFS="$OLDIFS"; unset OLDIFS
for _bash_it_config_file in "${_bash_it_config_files[@]}"; do
if [[ -e "$_bash_it_config_file" ]]; then
_set-prefix-based-on-path "${_bash_it_config_file}"
_log_debug "Loading component..."
Expand All @@ -44,7 +51,8 @@ if [[ -n "${2}" ]] && [[ -d "$BASH_IT/${2}/enabled" ]]; then
else
echo "Unable to locate ${_bash_it_config_file}" > /dev/stderr
fi
done ;;
done
unset _bash_it_config_files ;;
esac
fi

Expand Down

0 comments on commit d10a278

Please sign in to comment.