Skip to content
Open
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
6 changes: 5 additions & 1 deletion init/lmod/bash
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,11 @@ if [ -z "$__Init_EESSI_Default_Modules" ]; then
# (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 [ ! -z ${EESSI_MODULE_UPDATE_PS1} ] && [ ${EESSI_MODULE_UPDATE_PS1} -eq "0" ]; then
unset EESSI_MODULE_UPDATE_PS1
else
export EESSI_MODULE_UPDATE_PS1=1
fi
fi
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There were changed today and I suggest you start again from https://github.com/EESSI/software-layer-scripts/blob/main/init/lmod/sh.

General approach looks ok, but if you call the script twice the EESSI_MODULE_UPDATE_PS1 will be set on the second call. You probably want a structure similar to

if [ -z "$__Init_EESSI_PS1" ]; then
  export __Init_EESSI_PS1=1;
  ...
fi

You should also add a test for this case near https://github.com/EESSI/software-layer-scripts/blob/main/.github/workflows/scripts/test_init_scripts.sh#L145-L153

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the test it could be

TEST_EESSI_EXPLICIT_NO_PS1_UPDATE=$($shell -c "unset PS1 ; PS1='$ ' ; export EESSI_MODULE_UPDATE_PS1=0 ; . init/lmod/$shell 2>/dev/null ; echo \"\$PS1\"")
...
assert_raises 'echo "$TEST_EESSI_EXPLICIT_NO_PS1_UPDATE" | grep "$pattern"' 1


# Path to top-level module tree
Expand Down
6 changes: 5 additions & 1 deletion init/lmod/zsh
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,11 @@ if [ -z "$__Init_EESSI_Default_Modules" ]; then
# (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 [ ! -z ${EESSI_MODULE_UPDATE_PS1} ] && [ ${EESSI_MODULE_UPDATE_PS1} -eq "0" ]; then
unset EESSI_MODULE_UPDATE_PS1
else
export EESSI_MODULE_UPDATE_PS1=1
fi
fi

# Path to top-level module tree
Expand Down