2023-12-17 12:54:45 -08:00
|
|
|
module_confirm() {
|
|
|
|
local FILE
|
|
|
|
local DIR
|
|
|
|
local NAME
|
|
|
|
DIR=$1
|
|
|
|
NAME=$2
|
2024-03-01 15:01:47 -08:00
|
|
|
FILE="$(which find -L ${DIR} -type f -name "${NAME}.mod" -o -name "${NAME}".lib -o -name "${NAME}".func -o -name "${NAME}".sh -o -name "${NAME}".env)"
|
2023-12-17 12:54:45 -08:00
|
|
|
COUNT=0
|
|
|
|
if [ "$FILE" ]; then
|
|
|
|
COUNT=$(echo $FILE | xargs -n 1 | wc -l)
|
|
|
|
fi
|
|
|
|
if [ $COUNT -gt 1 ]; then
|
2024-02-21 11:11:07 -08:00
|
|
|
>&2 echo two or more modules of same name found, aborting
|
|
|
|
>&2 echo $FILE | xargs -n 1
|
2023-12-17 12:54:45 -08:00
|
|
|
return 1
|
|
|
|
fi
|
2024-02-21 11:11:07 -08:00
|
|
|
[[ $COUNT == 1 ]] && echo $FILE
|
2023-12-17 12:54:45 -08:00
|
|
|
}
|
|
|
|
module_find() {
|
2024-02-21 11:11:07 -08:00
|
|
|
[ ! $1 ] && >&2 echo "no module specified" && return 1
|
2023-12-17 12:54:45 -08:00
|
|
|
local MDIRS
|
|
|
|
local MDIR
|
|
|
|
local DIRS
|
|
|
|
local MODULE=$1
|
|
|
|
DIRS=( ${BASH_SHELL_DIRS:-$BASH_SHELL_BASE} ${BASH_SHELL_NETWORKS_LOADED} )
|
|
|
|
[ -d BASH_SHELL_USER_DIR ] && DIRS=("${DIRS[@]}" "BASH_SHELL_USER_DIR")
|
|
|
|
[ -d $BASH_SHELL_DEV ] && DIRS=("${DIRS[@]}" "$BASH_SHELL_DEV")
|
|
|
|
DIRS=("${DIRS[@]/%/\/modules}")
|
|
|
|
DIRS=("${MODULE_DIRS[@]}" "${DIRS[@]}")
|
|
|
|
cnt=${#DIRS[@]}
|
|
|
|
for ((i=1;i<=cnt;i++)); do
|
|
|
|
DIR="${DIRS[cnt-i]}"
|
|
|
|
if [[ -d $DIR ]]; then
|
|
|
|
RES=$(module_confirm "$DIR" "$MODULE")
|
|
|
|
[ $? -eq 0 ] && echo $RES && return 0
|
|
|
|
fi
|
|
|
|
done
|
2024-02-21 11:11:07 -08:00
|
|
|
>&2 echo no module found anywhere
|
2023-12-17 12:54:45 -08:00
|
|
|
return 1
|
|
|
|
|
|
|
|
}
|
|
|
|
module_load() {
|
2024-02-21 11:11:07 -08:00
|
|
|
local module;local mpath
|
|
|
|
[ ! $1 ] && >&2 echo "no module specified" && return 1
|
2023-12-17 12:54:45 -08:00
|
|
|
local FILE
|
2024-02-21 11:11:07 -08:00
|
|
|
for module in "$@"
|
|
|
|
do
|
|
|
|
eval "_${module}_ () { echo "$fname test"; }"
|
|
|
|
mpath=$(module_find $module)
|
|
|
|
[ $? -ne 0 ] && >&2 echo extreme warning: no module $1 found, so was not loaded
|
|
|
|
source $mpath "$@"
|
|
|
|
done
|
2023-12-17 12:54:45 -08:00
|
|
|
}
|
|
|
|
shell_run () {
|
|
|
|
bash -ci ". ${1}"
|
|
|
|
}
|