[cleanup] Harmonized variable names, added support for global config files

pull/1277/head
caguettaz 2018-12-04 14:30:11 +01:00
parent 2f3d4bd130
commit f06439edc3
2 changed files with 42 additions and 33 deletions

View File

@ -29,31 +29,28 @@ cite _about _param _example _group _author _version
# libraries, but skip appearance (themes) for now # libraries, but skip appearance (themes) for now
LIB="${BASH_IT}/lib/*.bash" LIB="${BASH_IT}/lib/*.bash"
APPEARANCE_LIB="${BASH_IT}/lib/appearance.bash" APPEARANCE_LIB="${BASH_IT}/lib/appearance.bash"
for config_file in $LIB for _bash_it_config_file in $LIB
do do
if [ "$config_file" != "$APPEARANCE_LIB" ]; then if [ "$_bash_it_config_file" != "$APPEARANCE_LIB" ]; then
# shellcheck disable=SC1090 # shellcheck disable=SC1090
source "$config_file" source "$_bash_it_config_file"
fi fi
done done
# Load the global "enabled" directory # Load the global "enabled" directory
_load_global_bash_it_files # "family" param is empty so that files get sources in glob order
for _bash_it_config_file in $(_list_global_bash_it_files "") ; do
. "${BASH_IT}/$_bash_it_config_file"
done
# Load enabled aliases, completion, plugins # Load enabled aliases, completion, plugins
for file_type in "aliases" "plugins" "completion" for file_type in "aliases" "plugins" "completion"
do do
_bash_it_list_bash_it_files_return=() for _bash_it_config_file in $(_list_bash_it_files "$file_type") ; do
_list_bash_it_files $file_type . "${BASH_IT}/$_bash_it_config_file"
for config_file in "${_bash_it_list_bash_it_files_return[@]}" ; do
. "$config_file"
done done
done done
unset _bash_it_list_bash_it_files_return
unset _bash_it_config_file
# Load theme, if a theme was set # Load theme, if a theme was set
if [[ ! -z "${BASH_IT_THEME}" ]]; then if [[ ! -z "${BASH_IT_THEME}" ]]; then
# Load colors and helpers first so they can be used in base theme # Load colors and helpers first so they can be used in base theme
@ -83,15 +80,15 @@ done
# Custom # Custom
CUSTOM="${BASH_IT_CUSTOM:=${BASH_IT}/custom}/*.bash ${BASH_IT_CUSTOM:=${BASH_IT}/custom}/**/*.bash" CUSTOM="${BASH_IT_CUSTOM:=${BASH_IT}/custom}/*.bash ${BASH_IT_CUSTOM:=${BASH_IT}/custom}/**/*.bash"
for config_file in $CUSTOM for _bash_it_config_file in $CUSTOM
do do
if [ -e "${config_file}" ]; then if [ -e "${_bash_it_config_file}" ]; then
# shellcheck disable=SC1090 # shellcheck disable=SC1090
source "$config_file" source "$_bash_it_config_file"
fi fi
done done
unset config_file unset _bash_it_config_file
if [[ $PROMPT ]]; then if [[ $PROMPT ]]; then
export PS1="\[""$PROMPT""\]" export PS1="\[""$PROMPT""\]"
fi fi

View File

@ -17,42 +17,54 @@ function _command_exists ()
# Helper function listing various enable-able files to be sourced # Helper function listing various enable-able files to be sourced
# The files need to be sourced in global scope to preserve scope of 'declare' # The files need to be sourced in global scope to preserve scope of 'declare'
function _list_bash_it_files() { function _list_bash_it_files() {
subdirectory="$1" local subdirectory="$1"
if [ -d "${BASH_IT}/${subdirectory}/enabled" ] pushd "${BASH_IT}" >/dev/null
if [ -d "./${subdirectory}/enabled" ]
then then
FILES="${BASH_IT}/${subdirectory}/enabled/*.bash" local FILES="./${subdirectory}/enabled/*.bash"
local _bash_it_config_file
for _bash_it_config_file in $FILES for _bash_it_config_file in $FILES
do do
if [ -e "${_bash_it_config_file}" ]; then if [ -e "${_bash_it_config_file}" ]; then
_bash_it_list_bash_it_files_return+=("$_bash_it_config_file") printf "$_bash_it_config_file\n"
fi fi
done done
fi fi
popd >/dev/null
} }
function _load_global_bash_it_files() { function _list_global_bash_it_files() {
local family="$1"
pushd "${BASH_IT}" >/dev/null
# In the new structure # In the new structure
if [ -d "${BASH_IT}/enabled" ] if [ -d "./enabled" ]
then then
FILES="${BASH_IT}/enabled/*.bash" local FILES="./enabled/*$family.bash"
for config_file in $FILES local _bash_it_config_file
for _bash_it_config_file in $FILES
do do
if [ -e "${config_file}" ]; then if [ -e "${_bash_it_config_file}" ]; then
source $config_file printf "$_bash_it_config_file\n"
fi fi
done done
fi fi
} }
function _make_reload_alias() { function _make_reload_alias() {
printf %s '\ printf %s '
_bash_it_list_bash_it_files_return=() ;\
_list_bash_it_files '"$1"' ;\ for _bash_it_config_file in $(_list_global_bash_it_files '"$1"'); do \
for _bash_it_config_file in "${_bash_it_list_bash_it_files_return[@]}"; do \ . "${BASH_IT}/$_bash_it_config_file" ;
. "$_bash_it_config_file" ;\ done ;
done ;\
unset _bash_it_list_bash_it_files_return ;\ for _bash_it_config_file in $(_list_bash_it_files '"$1"'); do
. "${BASH_IT}/$_bash_it_config_file" ;
done ;
unset _bash_it_config_file' unset _bash_it_config_file'
} }