Commit 840ae5d1 authored by gsell's avatar gsell

scripts/Bootstrap/Pmodules/bash:

- module() function cleanup
- build MANPATH from /etc/man.conf{ig}
parent 9ad827b3
......@@ -16,49 +16,26 @@ module() {
local -a args=()
local -a switches=()
local -a sub_switches=()
local subcommand=''
while (( $# > 0 )); do
while (( $# > 0 ));do
case $1 in
-u|--userlvl )
switches+=( $1 $2 )
shift 2
;;
-* )
switches+=( $1 )
shift
;;
[a-z]* )
subcommand=$1
shift
break
[/~a-zA-Z]* )
args+=( $1 )
;;
esac
done
while (( $# > 0 ));do
case $1 in
-* )
sub_switches+=( $1 )
;;
[/~a-zA-Z]* )
args+=( $1 )
;;
esac
shift
done
if [[ ${subcommand} == '' ]]; then
subcommand='help'
fi
if (( ${#args[@]} == 0 )); then
eval $( "${modulecmd}" bash ${switches[@]} "${subcommand}" "${sub_switches[@]}" )
else
for arg in "${args[@]}"; do
eval $( "${modulecmd}" bash ${switches[@]} "${subcommand}" "${sub_switches[@]}" "${arg}" )
done
fi
[[ ${#args[@]} == 0 ]] && args+=( 'help' )
[[ ${#args[@]} == 1 ]] && args+=( '--' )
local -i i=1
for (( i=1; i < ${#args[@]}; i++ )); do
eval $( "${modulecmd}" bash "${args[0]}" "${switches[@]}" "${args[i]}" )
done
}
export -f module
......@@ -91,6 +68,19 @@ prepend_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
}
#
# Replace or remove a directory in a path variable.
#
......@@ -154,7 +144,21 @@ unset PMODULES_DEFINED_RELEASES
replace_path PATH "${PMODULES_HOME%/*}/.*"
replace_path MANPATH "${PMODULES_HOME%/*}/.*"
append_path PATH "${PMODULES_HOME}/bin"
append_path MANPATH "${PMODULES_HOME}/share/man"
if [[ -r /etc/man.config ]]; then
declare _manconf='/etc/man.config'
elif [[ -r /etc/man.conf ]]; then
declare _manconf='/etc/man.conf'
fi
if [[ -n ${_manconf} ]]; then
while read name value rest; do
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"
fi
#############################################################################
# initialize bash completion
......
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