shell-network/modules/network-dirs.mod.del

60 lines
1.4 KiB
Plaintext
Raw Normal View History

#!/bin/bash
# to be sourced (below) not run in subshell!
2022-12-30 09:14:39 -08:00
function network_path () {
[[ ! $1 ]] && return 1
local network;
network=$1
[[ $2 ]] && network=$2/$network
if [[ $(isAbsPath $network) ]]; then
[[ ! -d $network ]] && continue
else
if [[ -d ${HOME}/${BASH_SHELL_USER}/${network} ]];then
network=${HOME}/${BASH_SHELL_USER}/${network}
else
if [[ -d ${BASH_NETWORKS_DIR}/${network} ]];then
network=${BASH_NETWORKS_DIR}/${network}
else
return 2
fi
fi
fi
echo $network
}
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
[[ ! $1 ]] && return 1
local networks;
networks=$1
2022-12-30 09:14:39 -08:00
[[ ! $1 ]] && return 2
[[ -f $1 ]] && networks=$(cat $1 | tr -s "\n" " ")
2022-12-30 09:14:39 -08:00
echo networks to add $networks
for network in $networks;
do
if [[ ${network} = *!* ]]; then
network=${network/!/}
BASH_NETWORK_HOME=$network
fi
2022-12-30 09:14:39 -08:00
network=$(network_path $network $2)
if [[ $network ]]; then
[[ $network =~ $BASH_NETWORK_HOME ]] && BASH_NETWORK_HOME_DIR=${network}
# echo adding $network to list of networks
BASH_SHELL_NETWORK_PATHS+="${network} "
fi
done
export BASH_NETWORK_HOME
export BASH_NETWORK_HOME_DIR
2022-12-30 09:14:39 -08:00
export BASH_SHELL_NETWORK_PATHS
}