2022-02-21 11:54:03 -08:00
|
|
|
#!/bin/bash
|
|
|
|
|
2022-12-30 09:18:39 -08:00
|
|
|
shell_source_subdirs () {
|
|
|
|
# default processing
|
|
|
|
[[ ! -d $1 ]] && echo no directory $1 from which to process subdirectories && return 1
|
2023-01-05 12:36:23 -08:00
|
|
|
local DIR
|
2022-12-30 09:18:39 -08:00
|
|
|
local SUBDIRS
|
|
|
|
local IGNORE_FILE
|
|
|
|
DIR=$1
|
2023-02-22 11:39:34 -08:00
|
|
|
SUBDIRS="load $([[ -f "$DIR/.bash-shell-include" ]] && cat "$DIR/.bash-shell-include" || cat "$BASH_SHELL_BASE/.bash-shell-include")"
|
2022-12-30 09:18:39 -08:00
|
|
|
[[ $SSH_SESSION ]] && SUBDIRS+=" ssh/session"
|
|
|
|
IGNORE_FILE="$([[ -f "$DIR/.bash-shell-ignore" ]] && echo "$DIR" || echo "$BASH_SHELL_BASE")/.bash-shell-ignore"
|
|
|
|
# echo $DIR
|
|
|
|
# echo $SUBDIRS
|
|
|
|
for SUBDIR in $SUBDIRS; do
|
|
|
|
if [ -e "$DIR/$SUBDIR" ]; then
|
|
|
|
# echo processing subdirectory $DIR/$SUBDIR
|
|
|
|
source_dir -f "$IGNORE_FILE" -d 0 $DIR/$SUBDIR
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2022-02-21 11:54:03 -08:00
|
|
|
function shell_process_directory () {
|
|
|
|
local SUBDIRS
|
|
|
|
local DIR
|
|
|
|
|
2024-02-16 23:49:08 -08:00
|
|
|
module_load source
|
2022-02-21 11:54:03 -08:00
|
|
|
[[ $? -ne 0 ]] && echo unable to access the file module, aborting load && return 1
|
|
|
|
|
|
|
|
DIR=${1:-$BASH_SHELL_BASE}
|
2022-12-30 09:18:39 -08:00
|
|
|
|
2022-05-02 10:46:41 -07:00
|
|
|
# echo sourcing directory $DIR
|
2022-02-21 11:54:03 -08:00
|
|
|
# if [[ $DIR = "$BASH_SHELL_BASE" ]]; then
|
|
|
|
# BASH_SHELL_IGNORE=$(shell_get_ignores)
|
|
|
|
# excludes=$BASH_SHELL_IGNORE
|
|
|
|
# else
|
|
|
|
# excludes=$(shell_get_ignores $DIR)
|
|
|
|
# [[ $? -ne 0 ]] && excludes=$BASH_SHELL_IGNORE
|
|
|
|
# fi
|
|
|
|
|
|
|
|
if [ -d "$DIR" ]; then
|
|
|
|
if [ "$DIR" = "$BASH_SHELL_BASE" ] && [ "$BASH_SHELL_BASE_LOADED" = "true" ]; then
|
|
|
|
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
|
|
|
|
# else
|
|
|
|
# echo non-interactive shell
|
|
|
|
# return 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ $DIR != "$BASH_SHELL_BASE" ]] && [[ -f $DIR/load.sh ]]; then
|
2022-12-30 09:18:39 -08:00
|
|
|
#
|
|
|
|
echo "$DIR/load.sh" found, running instead of base load.sh script
|
2022-02-21 11:54:03 -08:00
|
|
|
source "$DIR/load.sh"
|
|
|
|
else
|
2022-12-30 09:18:39 -08:00
|
|
|
shell_source_subdirs $DIR
|
2023-01-20 17:17:55 -08:00
|
|
|
fi
|
2022-02-21 11:54:03 -08:00
|
|
|
# echo "done sourcing directory $DIR"
|
|
|
|
# else
|
|
|
|
# echo $DIR does not exist nothing to source
|
|
|
|
fi
|
|
|
|
|
|
|
|
}
|
|
|
|
|