diff --git a/.github/workflows/scripts/test_init_scripts.sh b/.github/workflows/scripts/test_init_scripts.sh index 843e8d26..8fa958be 100755 --- a/.github/workflows/scripts/test_init_scripts.sh +++ b/.github/workflows/scripts/test_init_scripts.sh @@ -165,6 +165,14 @@ for shell in ${SHELLS[@]}; do TEST_EESSI_EXPLICIT_NO_PS1_UPDATE_CALLED_TWICE=$($shell -c "unset PS1 ; PS1='$ ' ; export EESSI_MODULE_UPDATE_PS1=0 ; . init/lmod/$shell 2>/dev/null ; . init/lmod/$shell 2>/dev/null ; echo \"\$PS1\"") assert_raises 'echo "$TEST_EESSI_EXPLICIT_NO_PS1_UPDATE" | grep "$pattern"' 1 assert_raises 'echo "$TEST_EESSI_EXPLICIT_NO_PS1_UPDATE_CALLED_TWICE" | grep "$pattern"' 1 + # Also check complex prompts, and unloading/purging the EESSI module + prompt="\$(echo '\['✘) $ " + promptstr="\[✘ $ " + updated_promptstr="{EESSI/${EESSI_VERSION}} \[✘ $ " + TEST_EESSI_PS1_UPDATE=$($shell -c "unset PS1 ; PS1=\"$prompt\" ; . init/lmod/$shell >/dev/null 2>&1 ; echo \"\$PS1\"") + TEST_EESSI_PS1_REVERT=$($shell -c "unset PS1 ; PS1=\"$prompt\" ; . init/lmod/$shell >/dev/null 2>&1 ; module purge; echo \"\$PS1\"") + assert 'echo "$TEST_EESSI_PS1_UPDATE"' "$updated_promptstr" + assert 'echo "$TEST_EESSI_PS1_REVERT"' "$promptstr" fi # End Test Suite diff --git a/init/modules/EESSI/2023.06.lua b/init/modules/EESSI/2023.06.lua index 7db50728..232caefd 100644 --- a/init/modules/EESSI/2023.06.lua +++ b/init/modules/EESSI/2023.06.lua @@ -222,7 +222,14 @@ local quiet_load = false if os.getenv("EESSI_MODULE_UPDATE_PS1") then local prompt = os.getenv("PS1") if prompt then - pushenv("PS1", "{EESSI/" .. eessi_version .. "} " .. prompt) + local prefix = "{EESSI/" .. eessi_version .. "} " + if mode() == "load" then + -- Prepend prefix to PS1 without evaluating its contents + execute{cmd="PS1='" .. prefix .. "'\"$PS1\"", modeA={"load"}} + elseif mode() == "unload" then + -- Strip the prefix from beginning of PS1 + execute{cmd="PS1=\"${PS1#'" .. prefix .. "'}\"", modeA={"unload"}} + end end end