shell-base/load.sh

89 lines
2.4 KiB
Bash
Executable File

#!/bin/bash
reload_shell () {
source $BASH_SHELL_BASE/load.sh $@
}
load_shell_host () {
module_load shell-process-directory
[[ $BASH_SHELL_HOST ]] && shell_process_directory $BASH_SHELL_HOST
}
load_shell_user () {
module_load shell-process-directory
[[ -d $HOME/${BASH_SHELL_USER:-shell} ]] && shell_process_directory $HOME/${BASH_SHELL_USER:-shell}
}
load_shell_dev () {
module_load shell-process-directory
[[ $BASH_SHELL_DEV ]] && shell_process_directory $BASH_SHELL_DEV
}
load_shell_host_user_dev () {
load_shell_host
load_shell_user
load_shell_dev
}
# 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
# process base any
for dir in ${1:-$BASH_SHELL_DIRS}; do
# env | grep BASH
# echo base $dir
shell_process_directory $dir
[[ "$dir" = "$BASH_SHELL_BASE" ]] && export BASH_SHELL_BASE_LOADED=true
done
# set one or the other of these in shell.env if you want to load networks with every shell
if [[ $BASH_SHELL_HOME_NETWORK_LOAD ]] || [[ $BASH_SHELL_NETWORKS_LOAD ]] || [[ $BASH_SHELL_NETWORK ]] ; then
if [[ $BASH_SHELL_ANY_NETWORK ]]; then
module_load networks
[[ $(is_function _load_networks) ]] && _load_networks $BASH_SHELL_NETWORK
fi
fi
load_shell_host_user_dev
export BASH_SHELL_LOADED=true
# Note: $HOME/shell or $HOME/BASH_SHELL_USER are processed via $HOME/.bashrc