Skip to content

Commit 655d651

Browse files
authored
Merge pull request #192 from adammccartney/configure_eessi_module_update_ps1
Add condition and test for explicit set of no PS1
2 parents 8865385 + b6aa04e commit 655d651

2 files changed

Lines changed: 14 additions & 3 deletions

File tree

.github/workflows/scripts/test_init_scripts.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,11 @@ for shell in ${SHELLS[@]}; do
150150
pattern="{EESSI/${EESSI_VERSION}} "
151151
assert_raises 'echo "$TEST_EESSI_PS1_UPDATE" | grep "$pattern"'
152152
assert_raises 'echo "$TEST_EESSI_NO_PS1_UPDATE" | grep "$pattern"' 1
153+
# Also check when we explicitly ask for it not to be updated
154+
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\"")
155+
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\"")
156+
assert_raises 'echo "$TEST_EESSI_EXPLICIT_NO_PS1_UPDATE" | grep "$pattern"' 1
157+
assert_raises 'echo "$TEST_EESSI_EXPLICIT_NO_PS1_UPDATE_CALLED_TWICE" | grep "$pattern"' 1
153158
fi
154159

155160
# End Test Suite

init/lmod/sh

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
# - The EESSI module also listens to environment variables so that it can be silently configured by a site
2626
# - EESSI_MODULE_FAMILY_NAME: use the value of the environment variable to set an Lmod family for the EESSI module
2727
# - EESSI_MODULE_STICKY: make the EESSI module sticky
28-
# - EESSI_MODULE_UPDATE_PS1: have the EESSI module update PS1 to give a prompt that is prepended with "{EESSI/...} " (requires exporting PS1)
28+
# - EESSI_MODULE_UPDATE_PS1: set to 1 (by default), the EESSI module prepends "{EESSI/...} " to PS1 (the shell prompt). Set to 0, PS1 remains unmodified.
2929
# (- EESSI_MODULE_DEBUG_INIT: enable debug print statements when loading the EESSI module)
3030
#
3131
# Effects:
@@ -97,8 +97,14 @@ if [ -z "$__Init_EESSI_Default_Modules" ]; then
9797
# For the shells that use PS1 for the prompt, let's add the trigger to enable updating that by default
9898
# (in an interactive shell PS1 is likely unset, so let's only do this if it is set)
9999
if [ -n "$PS1" ]; then
100-
export PS1
101-
export EESSI_MODULE_UPDATE_PS1=1
100+
if [ "${EESSI_MODULE_UPDATE_PS1-}" = "0" ] ; then
101+
# For certainty, we now unset it to guarantee it is not picked up by the EESSI module
102+
# (this guarantees PS1 is not updated, even if it is exported externally to this script)
103+
unset EESSI_MODULE_UPDATE_PS1
104+
else
105+
export EESSI_MODULE_UPDATE_PS1=1
106+
export PS1
107+
fi
102108
fi
103109

104110
# Figure out which shell was used to source this script, which we then use to source the corresponding

0 commit comments

Comments
 (0)