Skip to content

Commit 2280a99

Browse files
committed
ENH: pass DATALAD_CONTAINER_NAME inside the env and adjust PS1
DATALAD_CONTAINER_NAME is yet to be supported/set by datalad-container. PR: datalad/datalad-container#84 But decided also to improve the PS1 altogether so we could make PS1 less cryptic and set explicitly to point to being under singularity and also shorten the long annex key if using old singularity
1 parent fb5d9a6 commit 2280a99

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

binds/HOME/.bashrc

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,20 @@ if [ ! -z "$PS1" ]; then
33
# Since we are using git-annex for images, SINGULARITY_NAME would
44
# carry the dereferenced filename - git-annex key which is not
55
# that useful to see, so we just add [SING] marker
6-
if ! echo "$PS1" | grep -q SINGULARITY_NAME; then
7-
export PS1="${SINGULARITY_NAME:+[SING]}$PS1"
6+
if ! echo "$PS1" | grep -q SINGULARITY_NAME && [ ! -z "$SINGULARITY_NAME" ]; then
7+
# proposed in https://github.com/datalad/datalad-container/pull/84
8+
if [ ! -z "${DATALAD_CONTAINER_NAME:-}" ]; then
9+
_name="$DATALAD_CONTAINER_NAME"
10+
elif echo "$SINGULARITY_NAME" | grep -q '^MD5E-'; then
11+
# singularity < 3. dereferences symlinks -
12+
# annexed keys are too long/useless in this context, we shorten
13+
_name=$(echo ${SINGULARITY_NAME##*--} | cut -c 1-8)...
14+
else
15+
_name="$SINGULARITY_NAME"
16+
fi
17+
# strip our possible suffix
18+
_name="$(echo $_name | sed -e 's,.sing$,,g')"
19+
export PS1="singularity:$_name > $PS1"
820
fi
921
fi
1022

scripts/singularity_cmd

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ updir=$(dirname "$thisdir")
4242

4343
cmd="$1"; shift
4444

45+
if [ ! -z "${DATALAD_CONTAINER_NAME:-}" ]; then
46+
export SINGULARITYENV_DATALAD_CONTAINER_NAME="$DATALAD_CONTAINER_NAME"
47+
fi
48+
4549
# singularity bind mounts system /tmp, which might result in side-effects
4650
# Create a dedicated temporary directory to be removed upon completion
4751
tmpdir=$(mktemp -d --suffix=singtmp)

0 commit comments

Comments
 (0)