This repository has been archived on 2022-02-20. You can view files and clone it, but cannot push or open issues/pull-requests.
2020-11-13 10:25:04 -08:00
|
|
|
#!/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
|
2020-12-26 12:54:47 -08:00
|
|
|
if ([[ -d "$1" ]] || [[ ! $1 = /* ]]); then
|
2020-11-13 10:25:04 -08:00
|
|
|
local PATHVARIABLE=${2:-PATH}
|
|
|
|
export $PATHVARIABLE="$1${!PATHVARIABLE:+:${!PATHVARIABLE}}"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
path_append () {
|
|
|
|
path_remove $1 $2
|
2020-12-26 12:54:47 -08:00
|
|
|
if ([[ -d "$1" ]] || [[ ! $1 = /* ]]); then
|
2020-11-13 10:25:04 -08:00
|
|
|
local PATHVARIABLE=${2:-PATH}
|
|
|
|
export $PATHVARIABLE="${!PATHVARIABLE:+${!PATHVARIABLE}:}$1"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
path_insert () {
|
2020-12-26 12:54:47 -08:00
|
|
|
if ([[ -d "$1" ]] || [[ ! $1 = /* ]]); then
|
2020-11-13 10:25:04 -08:00
|
|
|
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 "$@"
|
|
|
|
# }
|