Skip to content

Commit f3f5aef

Browse files
committed
Make shells that use PS1 update it by default
1 parent 994a8a1 commit f3f5aef

4 files changed

Lines changed: 32 additions & 1 deletion

File tree

.github/workflows/scripts/test_init_scripts.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,14 @@ for shell in ${SHELLS[@]}; do
138138
assert_raises 'echo "$TEST_EESSI_WITHOUT_PURGE" | grep "$pattern"' 1
139139
fi
140140

141+
# Optional test 10, check if the prompt has been updated
142+
if [ "$shell" = "bash" ] || [ "$shell" = "ksh" ] || [ "$shell" = "zsh" ]; then
143+
# Typically this is a non-interactive shell, so manually set PS1 when testing
144+
TEST_EESSI_PS1_UPDATE=$($shell -c "PS1='$ ' ; source init/lmod/$shell 2>/dev/null ; echo \"\$PS1\"")
145+
pattern="{EESSI/${EESSI_VERSION}}"
146+
assert_raises 'echo "$TEST_EESSI_PS1_UPDATE" | grep "$pattern"'
147+
fi
148+
141149
# End Test Suite
142150
assert_end "source_eessi_$shell"
143151

init/lmod/bash

Lines changed: 8 additions & 1 deletion
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/...} "
28+
# - EESSI_MODULE_UPDATE_PS1: have the EESSI module update PS1 to give a prompt that is prepended with "{EESSI/...} " (requires exporting PS1)
2929
# (- EESSI_MODULE_DEBUG_INIT: enable debug print statements when loading the EESSI module)
3030
#
3131
# Effects:
@@ -89,6 +89,13 @@ if [ -z "$__Init_EESSI_Default_Modules" ]; then
8989
# - and clear out any memory Lmod might have
9090
unset _ModuleTable001_
9191

92+
# For the shells that use PS1 for the prompt, let's add the trigger to enable updating that by default
93+
# (in an interactive shell PS1 is likely unset, so let's only do this if it is set)
94+
if [ -n "$PS1" ]; then
95+
export PS1
96+
export EESSI_MODULE_UPDATE_PS1=1
97+
fi
98+
9299
# Path to top-level module tree
93100
# - EESSI_EXTRA_MODULEPATH environment variable allows a site to append to MODULEPATH (lower priority than EESSI MODULEPATH)
94101
export MODULEPATH="${EESSI_CVMFS_REPO}/init/modules${EESSI_EXTRA_MODULEPATH:+:$EESSI_EXTRA_MODULEPATH}"

init/lmod/ksh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,14 @@ if [ -z "$__Init_EESSI_Default_Modules" ]; then
4444
unset __LMOD_REF_COUNT_MODULEPATH
4545
# and clear out any memory Lmod might have
4646
unset _ModuleTable001_
47+
48+
# For the shells that use PS1 for the prompt, let's add the trigger to enable updating that by default
49+
# (in an interactive shell PS1 is likely unset, so let's only do this if it is set)
50+
if [ -n "$PS1" ]; then
51+
export PS1
52+
export EESSI_MODULE_UPDATE_PS1=1
53+
fi
54+
4755
# Path to top-level module tree
4856
export MODULEPATH="${EESSI_CVMFS_REPO}/init/modules${EESSI_EXTRA_MODULEPATH:+:$EESSI_EXTRA_MODULEPATH}"
4957
. "${EESSI_CVMFS_REPO}/versions/${LMOD_EESSI_VERSION}/compat/linux/$(uname -m)/usr/share/Lmod/init/ksh"

init/lmod/zsh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,14 @@ if [ -z "$__Init_EESSI_Default_Modules" ]; then
4444
unset __LMOD_REF_COUNT_MODULEPATH
4545
# and clear out any memory Lmod might have
4646
unset _ModuleTable001_
47+
48+
# For the shells that use PS1 for the prompt, let's add the trigger to enable updating that by default
49+
# (in an interactive shell PS1 is likely unset, so let's only do this if it is set)
50+
if [ -n "$PS1" ]; then
51+
export PS1
52+
export EESSI_MODULE_UPDATE_PS1=1
53+
fi
54+
4755
# Path to top-level module tree
4856
export MODULEPATH="${EESSI_CVMFS_REPO}/init/modules${EESSI_EXTRA_MODULEPATH:+:$EESSI_EXTRA_MODULEPATH}"
4957
. "${EESSI_CVMFS_REPO}/versions/${LMOD_EESSI_VERSION}/compat/linux/$(uname -m)/usr/share/Lmod/init/zsh"

0 commit comments

Comments
 (0)