shell-base/load.sh

54 lines
1.5 KiB
Bash
Executable File

#!/bin/bash
# PRIMARY SHELL LOAD SCRIPT - RUN FOR ALL INTERACTIVE SHELLS
# don't bother if bash is not the shell
[ ! "$SHELL" = "/bin/bash" ] && return 1
# ************ be sure module_load function is availABLE ***************************
[[ $(declare -F | grep module_load) ]] || source "$BASH_SHELL_BASE/module.lib"
module_load debug
if [[ $? -ne 0 ]]; then
echo "unable to load a 'debug' module using a noop for debug function"
# noop
function debug () {
:
}
fi
([[ $BASH_ENV ]] && [[ ! $- == *i* ]] && [[ $BASH_USE_ALIAS ]]) && shopt -s expand_aliases
# process the base directory by default
unset BASH_SHELL_BASE_LOADED
unset BASH_SHELL_LOADED
module_load shell-process-directory
if [[ $SSH_SESSION ]]; then
# ssh session only process base by default
# env | grep SSH
# echo ssh session bash load
# TODO process network dirs if environment variable is set
# process only base, nothing (i.e. BASH_SAFE_MODE, SSH_SHELL_CLEAN) if env variables are set
# see https://stackoverflow.com/a/59461195
shell_process_directory $BASH_SHELL_BASE
shell_process_directory $BASH_SHELL_ANY_HOST
shell_process_directory $BASH_SHELL_HOST
export BASH_SHELL_BASE_LOADED=true
else
# local shell so process all directories
for dir in ${1:-$BASH_SHELL_DIRS}; do
# env | grep BASH
# echo $dir
shell_process_directory $dir
[[ "$dir" = "$BASH_SHELL_BASE" ]] && export BASH_SHELL_BASE_LOADED=true
done
fi
export BASH_SHELL_LOADED=true
# Note: $HOME/shell or $HOME/BASH_SHELL_USER are processed via $HOME/.bashrc