shell-base/function/02-path
David Kebler 0ac5906eee refactor the way the module library is loaded
added startup script callable from profile.d
renamed setup.sh to load.sh
added rsync copy function cprs
added shell.env that is called by /etc/profile to set up access to this  and related repos
2020-11-13 10:25:04 -08:00

49 lines
1.1 KiB
Bash

#!/bin/bash
path_remove () {
local IFS=':'
local NEWPATH
local DIR
local PATHVARIABLE=${2:-PATH}
for DIR in ${!PATHVARIABLE} ; do
if [ "$DIR" != "$1" ] ; then
NEWPATH=${NEWPATH:+$NEWPATH:}$DIR
fi
done
export $PATHVARIABLE="$NEWPATH"
}
path_prepend () {
path_remove $1 $2
if [ -d "$1" ]; then
local PATHVARIABLE=${2:-PATH}
export $PATHVARIABLE="$1${!PATHVARIABLE:+:${!PATHVARIABLE}}"
fi
}
path_append () {
path_remove $1 $2
if [ -d "$1" ]; then
local PATHVARIABLE=${2:-PATH}
export $PATHVARIABLE="${!PATHVARIABLE:+${!PATHVARIABLE}:}$1"
fi
}
path_insert () {
if [ -d "$1" ]; then
local PATHVAR=${4:-PATH}
local temp
echo inserting $1 into ${!PATHVAR} $2 $3
boa=$([[ $2 == b* ]] && echo "$1:&" || echo "&:$1:")
temp="$(echo ${!PATHVAR} | sed -r "s#$3(:)?#$boa#" | sed 's#^:##' | sed 's#\:$##' | sed 's#::#:#g' )"
echo result: $temp
export PATHVAR=$temp
fi
}
# path_insert_before () {
# _path_insert b "$@"
# }
#
# path_insert_after () {
# _path_insert a "$@"
# }