Commit c51c004e authored by gsell's avatar gsell

bash init-file:

- namespace added to function, which should be replaced by
  functions from lib.bash
parent b697f630
......@@ -42,7 +42,7 @@ export -f module
#############################################################################
# helper functions
#
append_path () {
std::append_path () {
local -r P=$1
local -r d=$2
......@@ -55,40 +55,14 @@ append_path () {
fi
}
prepend_path () {
local -r P=$1
local -r d=$2
if ! echo ${!P} | egrep -q "(^|:)${d}($|:)" ; then
if [[ -z ${!P} ]]; then
eval $P=${d}
else
eval $P="${d}:${!P}"
fi
fi
}
prepend_path () {
local -r P=$1
local -r d=$2
if ! echo ${!P} | egrep -q "(^|:)${d}($|:)" ; then
if [[ -z ${!P} ]]; then
eval $P=${d}
else
eval $P="${d}:${!P}"
fi
fi
}
#
# Replace or remove a directory in a path variable.
#
# To remove a dir:
# replace_path PATH <pattern>
# std::replace_path PATH <pattern>
#
# To replace a dir:
# replace_path PATH <pattern> /replacement/path
# std::replace_path PATH <pattern> /replacement/path
#
# Args:
# $1 name of the shell variable to set (e.g. PATH)
......@@ -98,7 +72,7 @@ prepend_path () {
# Based on solution published here:
# https://stackoverflow.com/questions/273909/how-do-i-manipulate-path-elements-in-shell-scripts
#
replace_path () {
std::replace_path () {
local -r path=$1
local -r removepat=$2
local -r replacestr=$3
......@@ -127,12 +101,12 @@ declare -x _LMFILES_=''
declare -x PMODULES_USED_GROUPS=''
declare -x MODULEPATH=''
for group in ${PMODULES_DEFAULT_GROUPS//:/ }; do
append_path MODULEPATH "${PMODULES_ROOT}/${group}/${PMODULES_MODULEFILES_DIR}"
append_path PMODULES_USED_GROUPS "${group}"
std::append_path MODULEPATH "${PMODULES_ROOT}/${group}/${PMODULES_MODULEFILES_DIR}"
std::append_path PMODULES_USED_GROUPS "${group}"
done
declare -x UsedReleases=''
for r in ${PMODULES_DEFAULT_RELEASES//:/ }; do
append_path UsedReleases "${r}"
std::append_path UsedReleases "${r}"
done
eval $(save_env UsedReleases PMODULES_DEFAULT_RELEASES PMODULES_DEFAULT_GROUPS PMODULES_DEFINED_RELEASES)
......@@ -141,9 +115,9 @@ unset PMODULES_DEFAULT_RELEASES
unset PMODULES_DEFAULT_GROUPS
unset PMODULES_DEFINED_RELEASES
replace_path PATH "${PMODULES_HOME%/*}/.*"
replace_path MANPATH "${PMODULES_HOME%/*}/.*"
append_path PATH "${PMODULES_HOME}/bin"
std::replace_path PATH "${PMODULES_HOME%/*}/.*"
std::replace_path MANPATH "${PMODULES_HOME%/*}/.*"
std::append_path PATH "${PMODULES_HOME}/bin"
if [[ -r /etc/man.config ]]; then
declare _manconf='/etc/man.config'
......@@ -152,12 +126,12 @@ elif [[ -r /etc/man.conf ]]; then
fi
if [[ -n ${_manconf} ]]; then
while read name value rest; do
append_path MANPATH "${value}"
std::append_path MANPATH "${value}"
done < <(grep "^MANPATH\s" "${_manconf}")
unset _manconf
else
append_path MANPATH "${PMODULES_HOME}/share/man"
append_path MANPATH "/usr/share/man"
std::append_path MANPATH "${PMODULES_HOME}/share/man"
std::append_path MANPATH "/usr/share/man"
fi
#############################################################################
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment