54 lines
1.3 KiB
Plaintext
54 lines
1.3 KiB
Plaintext
|
module_confirm() {
|
||
|
local FILE
|
||
|
local DIR
|
||
|
local NAME
|
||
|
DIR=$1
|
||
|
NAME=$2
|
||
|
FILE="$(command find -L ${DIR} -type f -name "${NAME}.mod" -o -name "${NAME}".lib -o -name "${NAME}".func -o -name "${NAME}".sh -o -name "${NAME}".env)"
|
||
|
COUNT=0
|
||
|
if [ "$FILE" ]; then
|
||
|
COUNT=$(echo $FILE | xargs -n 1 | wc -l)
|
||
|
fi
|
||
|
if [ $COUNT -gt 1 ]; then
|
||
|
echo two or more modules of same name found, aborting
|
||
|
echo $FILE | xargs -n 1
|
||
|
return 1
|
||
|
fi
|
||
|
[ $COUNT == 1 ] && echo $FILE && return 0
|
||
|
return 1
|
||
|
}
|
||
|
module_find() {
|
||
|
[ ! $1 ] && echo "no module specified" && return 1
|
||
|
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
|
||
|
return 1
|
||
|
|
||
|
}
|
||
|
module_load() {
|
||
|
[ ! $1 ] && echo "no module specified" && return 1
|
||
|
local FILE
|
||
|
FILE=$(module_find $1)
|
||
|
[ $? -ne 0 ] && echo no module $1 found && return 1
|
||
|
shift 1
|
||
|
source $FILE "$@"
|
||
|
return 0
|
||
|
}
|
||
|
shell_run () {
|
||
|
bash -ci ". ${1}"
|
||
|
}
|