shell-base/modules/network-dirs.sh

40 lines
1.1 KiB
Bash
Raw Normal View History

# to be sourced (below) not run in subshell!
function network_dirs () {
(return 0 2>/dev/null) || (echo network_dirs must be sourced; return 1)
module_load path
[[ $? -ne 0 ]] && echo unable to access the file module, aboarting load && return 1
local network
[[ ! -f $1 ]] && return
while read -r network || [ -n "$network" ]
do
if [[ ${network} = *!* ]]; then
network=${network/!/}
NETWORK_HOME=$network
fi
[[ $2 ]] && network=$2/$network
if [[ $(isAbsPath $network) ]]; then
[[ ! -d $network ]] && continue
else
if [[ -d ${BASH_SHELL_USER}/${network} ]];then
network=${BASH_SHELL_USER}/${network}
else
if [[ -d ${BASH_NETWORKS_DIR}/${network} ]];then
network=${BASH_NETWORKS_DIR}/${network}
else
continue
fi
fi
fi
[[ $network =~ $NETWORK_HOME ]] && NETWORK_HOME_DIR=${network}
BASH_SHELL_NETWORK_DIRS+="${network} "
BASH_SHELL_DIRS+="${network} "
done < "$1"
export NETWORK_HOME
export NETWORK_HOME_DIR
export BASH_SHELL_NETWORK_DIRS
}