2020-11-03 12:07:49 -08:00
|
|
|
#!/bin/bash
|
|
|
|
DIR=${1:-$(dirname ${BASH_SOURCE[0]})}
|
|
|
|
|
|
|
|
# source the required directory source function
|
|
|
|
if [ ! -e "$BASH_SHELL_BASE/source-dir.func" ]; then
|
|
|
|
echo "!Unable to load sourcing function at $DIR/source-dir, shell not set up!"
|
|
|
|
else
|
|
|
|
. $BASH_SHELL_BASE/source-dir.func
|
|
|
|
# source the default shopt options
|
|
|
|
[ -e "$DIR/options" ] && . $DIR/options
|
|
|
|
|
|
|
|
function shell_process_directory () {
|
|
|
|
local SUBDIRS
|
|
|
|
local DIR
|
|
|
|
local DSUBDIRS
|
|
|
|
|
|
|
|
DIR=${1:-$BASH_SHELL_BASE}
|
2020-11-06 14:24:10 -08:00
|
|
|
# echo soucring directory $DIR
|
2020-11-03 12:07:49 -08:00
|
|
|
|
|
|
|
if [ -d "$DIR" ]; then
|
2020-11-06 14:24:10 -08:00
|
|
|
if [ "$DIR" = "$BASH_SHELL_BASE" ] && [ "$BASH_SHELL_BASE_SOURCED" = "true" ]; then
|
2020-11-03 12:07:49 -08:00
|
|
|
if [ -v PS1 ]; then
|
|
|
|
echo base directory already sourced
|
|
|
|
read -p "do you want to re-source the base (not recommended)? " -n 1 -r
|
|
|
|
echo
|
|
|
|
[[ ! $REPLY =~ ^[Yy]$ ]] && return 1
|
2020-11-06 14:24:10 -08:00
|
|
|
# else
|
|
|
|
# echo non-interactive shell
|
|
|
|
# return 1
|
2020-11-03 12:07:49 -08:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -f "$DIR/setup.sh" ] && [ "$DIR" != "$BASH_SHELL_BASE" ]; then
|
|
|
|
echo "$DIR/setup.sh" found, running instead of default processing
|
|
|
|
. "$DIR/setup.sh"
|
|
|
|
else
|
|
|
|
# default processing
|
|
|
|
local SUBDIRS
|
|
|
|
local DSUBDIRS
|
|
|
|
# default subdirectories to source
|
|
|
|
DSUBDIRS="env function alias misc lang app"
|
|
|
|
IFS=' ' read -r -a SUBDIRS <<< "${2:-$DSUBDIRS}"
|
|
|
|
# echo ${SUBDIRS[@]}
|
|
|
|
for SUBDIR in "${SUBDIRS[@]}"
|
|
|
|
do
|
|
|
|
if [ -e "$DIR/$SUBDIR" ]; then
|
2020-11-06 14:24:10 -08:00
|
|
|
# echo processing subdirectory $DIR/$SUBDIR
|
2020-11-03 12:07:49 -08:00
|
|
|
# must quote all globs to avoid bash glob expansion which is likely on
|
|
|
|
source_dir -p "archive" -x '"*.off" "*.md"' -d 0 $DIR/$SUBDIR
|
2020-11-06 14:24:10 -08:00
|
|
|
# else
|
|
|
|
# echo no subdirectory $DIR/$SUBDIR to process, ignorning
|
2020-11-03 12:07:49 -08:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
fi
|
2020-11-06 14:24:10 -08:00
|
|
|
# echo "done sourcing directory $DIR"
|
|
|
|
# else
|
|
|
|
# echo $DIR does not exist nothing to source
|
2020-11-03 12:07:49 -08:00
|
|
|
fi
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
# process the base directory by default
|
|
|
|
unset BASH_SHELL_BASE_SOURCED
|
|
|
|
shell_process_directory
|
|
|
|
export BASH_SHELL_BASE_SOURCED=true
|
|
|
|
# process network
|
|
|
|
shell_process_directory "$BASH_SHELL_NETWORK/all"
|
|
|
|
[ $NETWORKNAME ] && shell_process_directory "$BASH_SHELL_NETWORK/$NETWORKNAME"
|
|
|
|
# process host
|
|
|
|
shell_process_directory "$BASH_SHELL_HOST/all"
|
|
|
|
shell_process_directory "$BASH_SHELL_HOST/$(hostname)"
|
|
|
|
# process user
|
|
|
|
# Note: $HOME/shell or $HOME/BASH_SHELL_USER are sourced via $HOME/.bashrc
|
|
|
|
|
2020-11-06 14:24:10 -08:00
|
|
|
# echo $(envg BASH) | xargs -n 1
|
2020-11-03 12:07:49 -08:00
|
|
|
|
|
|
|
fi
|