Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/workflows/scripts/test_init_scripts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,11 @@ for shell in ${SHELLS[@]}; do
pattern="{EESSI/${EESSI_VERSION}} "
assert_raises 'echo "$TEST_EESSI_PS1_UPDATE" | grep "$pattern"'
assert_raises 'echo "$TEST_EESSI_NO_PS1_UPDATE" | grep "$pattern"' 1
# Also check when we explicitly ask for it not to be updated
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\"")
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
fi

# End Test Suite
Expand Down
12 changes: 9 additions & 3 deletions init/lmod/sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
# - The EESSI module also listens to environment variables so that it can be silently configured by a site
# - EESSI_MODULE_FAMILY_NAME: use the value of the environment variable to set an Lmod family for the EESSI module
# - EESSI_MODULE_STICKY: make the EESSI module sticky
# - EESSI_MODULE_UPDATE_PS1: have the EESSI module update PS1 to give a prompt that is prepended with "{EESSI/...} " (requires exporting PS1)
# - 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.
# (- EESSI_MODULE_DEBUG_INIT: enable debug print statements when loading the EESSI module)
#
# Effects:
Expand Down Expand Up @@ -97,8 +97,14 @@ if [ -z "$__Init_EESSI_Default_Modules" ]; then
# For the shells that use PS1 for the prompt, let's add the trigger to enable updating that by default
# (in an interactive shell PS1 is likely unset, so let's only do this if it is set)
if [ -n "$PS1" ]; then
export PS1
export EESSI_MODULE_UPDATE_PS1=1
if [ "${EESSI_MODULE_UPDATE_PS1-}" = "0" ] ; then
# For certainty, we now unset it to guarantee it is not picked up by the EESSI module
# (this guarantees PS1 is not updated, even if it is exported externally to this script)
unset EESSI_MODULE_UPDATE_PS1
else
export EESSI_MODULE_UPDATE_PS1=1
export PS1
fi
fi

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