diff --git a/Pmodules/libpmodules.bash.in b/Pmodules/libpmodules.bash.in index cab81e4..69bc53e 100644 --- a/Pmodules/libpmodules.bash.in +++ b/Pmodules/libpmodules.bash.in @@ -79,6 +79,7 @@ declare -A OverlayConfigKeys=( ['modulefiles_root']='' ['excludes']='' ['type']='n' + ['modulepath']='' ) pm::get_value(){ @@ -186,6 +187,13 @@ pm::read_config(){ printf -v excludes "%s:" "${tmp_array[@]}" OverlayInfo[${ol_name}:excludes]=$(${envsubst} <<<"${excludes%:}" ) ;; + modulepath ) + pm::get_seq "${yaml_input}" value "${key}" '!!seq' + local -a tmp_array=() + readarray -t tmp_array <<<${value} + local modulepath='' + printf -v modulepath "%s:" "${tmp_array[@]}" + OverlayInfo[${ol_name}:modulepath]=$(${envsubst} <<< "${modulepath%:}") ;; esac done diff --git a/Pmodules/modulecmd.bash.in b/Pmodules/modulecmd.bash.in index 3b3fa34..35a1adf 100644 --- a/Pmodules/modulecmd.bash.in +++ b/Pmodules/modulecmd.bash.in @@ -1685,6 +1685,15 @@ subcommand_use() { fi done + if [[ -v OverlayInfo[${ol_name}:modulepath] && \ + -n "${OverlayInfo[${ol_name}:modulepath]}" ]]; then + local -a modulepath=() + IFS=':' read -r -a modulepath <<<"${OverlayInfo[${ol_name}:modulepath]}" + local -- dir='' + for dir in "${modulepath[@]}"; do + std::prepend_path MODULEPATH "${dir}" + done + fi UsedOverlays=( "${ol_name}" "${UsedOverlays[@]}" ) OverlayInfo[${ol_name}:used]='yes' @@ -1866,13 +1875,25 @@ subcommand_unuse() { done done - EnvMustBeSaved='yes' - export_env UsedOverlays + # remove additional directories added overlay + if [[ -v OverlayInfo[${ol_name}:modulepath] && \ + -n "${OverlayInfo[${ol_name}:modulepath]}" ]]; then + local -a modulepath=() + IFS=':' read -r -a modulepath <<<"${OverlayInfo[${ol_name}:modulepath]}" + local -- dir='' + for dir in "${modulepath[@]}"; do + std::remove_path MODULEPATH "${dir}" + done + fi + + # remove root of overlay local dir for dir in "${modulepath[@]}"; do [[ "${dir}" == "${OverlayInfo[${ol_name}:modulefiles_root]}" ]] && \ std::remove_path MODULEPATH "${dir}" done + export_env UsedOverlays + EnvMustBeSaved='yes' } #..............................................................