Skip to content

Commit 30ca324

Browse files
authored
Merge pull request #196 from smoors/ps1
fix EESSI prefix for complex prompts
2 parents 47bc30f + 66f1bc0 commit 30ca324

2 files changed

Lines changed: 25 additions & 5 deletions

File tree

.github/workflows/scripts/test_init_scripts.sh

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,17 +154,30 @@ for shell in ${SHELLS[@]}; do
154154

155155
# Optional test 11, check if the prompt has been updated
156156
if [ "$shell" = "bash" ] || [ "$shell" = "ksh" ] || [ "$shell" = "zsh" ] || [ "$shell" = "sh" ]; then
157+
# Let's configure things to use the EESSI module within the PR
158+
sed 's|export MODULEPATH=.*|export MODULEPATH=init/modules|' init/lmod/sh >init/lmod/sh.test
159+
ln -srf init/lmod/sh.test init/lmod/bash.test
160+
ln -srf init/lmod/sh.test init/lmod/ksh.test
161+
ln -srf init/lmod/sh.test init/lmod/zsh.test
157162
# Typically this is a non-interactive shell, so manually unset PS1 and reset to a non-exported variable when testing
158-
TEST_EESSI_PS1_UPDATE=$($shell -c "unset PS1 ; PS1='$ ' ; . init/lmod/$shell 2>/dev/null ; echo \"\$PS1\"")
159-
TEST_EESSI_NO_PS1_UPDATE=$($shell -c "unset PS1 ; . init/lmod/$shell 2>/dev/null ; echo \"\$PS1\"")
163+
TEST_EESSI_PS1_UPDATE=$($shell -c "unset PS1 ; PS1='$ ' ; . init/lmod/$shell.test 2>/dev/null ; echo \"\$PS1\"")
164+
TEST_EESSI_NO_PS1_UPDATE=$($shell -c "unset PS1 ; . init/lmod/$shell.test 2>/dev/null ; echo \"\$PS1\"")
160165
pattern="{EESSI/${EESSI_VERSION}} "
161166
assert_raises 'echo "$TEST_EESSI_PS1_UPDATE" | grep "$pattern"'
162167
assert_raises 'echo "$TEST_EESSI_NO_PS1_UPDATE" | grep "$pattern"' 1
163168
# Also check when we explicitly ask for it not to be updated
164-
TEST_EESSI_EXPLICIT_NO_PS1_UPDATE=$($shell -c "unset PS1 ; PS1='test> ' ; export EESSI_MODULE_UPDATE_PS1=0 ; . init/lmod/$shell 2>/dev/null ; echo \"\$PS1\"")
165-
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\"")
169+
TEST_EESSI_EXPLICIT_NO_PS1_UPDATE=$($shell -c "unset PS1 ; PS1='test> ' ; export EESSI_MODULE_UPDATE_PS1=0 ; . init/lmod/$shell.test 2>/dev/null ; echo \"\$PS1\"")
170+
TEST_EESSI_EXPLICIT_NO_PS1_UPDATE_CALLED_TWICE=$($shell -c "unset PS1 ; PS1='$ ' ; export EESSI_MODULE_UPDATE_PS1=0 ; . init/lmod/$shell.test 2>/dev/null ; . init/lmod/$shell.test 2>/dev/null ; echo \"\$PS1\"")
166171
assert_raises 'echo "$TEST_EESSI_EXPLICIT_NO_PS1_UPDATE" | grep "$pattern"' 1
167172
assert_raises 'echo "$TEST_EESSI_EXPLICIT_NO_PS1_UPDATE_CALLED_TWICE" | grep "$pattern"' 1
173+
# Also check complex prompts, and unloading/purging the EESSI module
174+
prompt="\$(echo '\['✘) $ "
175+
promptstr="\[✘ $ "
176+
updated_promptstr="{EESSI/${EESSI_VERSION}} \[✘ $ "
177+
TEST_EESSI_PS1_UPDATE=$($shell -c "unset PS1 ; PS1=\"$prompt\" ; . init/lmod/$shell.test >/dev/null ; echo \"\$PS1\"")
178+
TEST_EESSI_PS1_REVERT=$($shell -c "unset PS1 ; PS1=\"$prompt\" ; . init/lmod/$shell.test >/dev/null ; module purge; echo \"\$PS1\"")
179+
assert 'echo "$TEST_EESSI_PS1_UPDATE"' "$updated_promptstr"
180+
assert 'echo "$TEST_EESSI_PS1_REVERT"' "$promptstr"
168181
fi
169182

170183
# End Test Suite

init/modules/EESSI/2023.06.lua

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,14 @@ local quiet_load = false
222222
if os.getenv("EESSI_MODULE_UPDATE_PS1") then
223223
local prompt = os.getenv("PS1")
224224
if prompt then
225-
pushenv("PS1", "{EESSI/" .. eessi_version .. "} " .. prompt)
225+
local prefix = "{EESSI/" .. eessi_version .. "} "
226+
if mode() == "load" then
227+
-- Prepend prefix to PS1 without evaluating its contents
228+
execute{cmd="PS1=\"" .. prefix .. "$PS1\"", modeA={"load"}}
229+
elseif mode() == "unload" then
230+
-- Strip the prefix from beginning of PS1
231+
execute{cmd="PS1=\"${PS1#\"" .. prefix .. "\"}\"", modeA={"unload"}}
232+
end
226233
end
227234
end
228235

0 commit comments

Comments
 (0)