Skip to content

Commit 9ca2105

Browse files
scheibelppearce8
andauthored
Robust setup env (#1246)
* setup script edits * substring check is no longer fooled by a venv stored in the benchpark root * add some explanatory comments * support only bash and zsh; expand comment --------- Co-authored-by: pearce8 <pearce8@llnl.gov>
1 parent abd887c commit 9ca2105

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

setup-env.sh

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,25 @@
1-
export PATH=${PWD}/bin:$PATH
1+
if [ -n "${BASH_VERSION-}" ]; then
2+
_this_file=${BASH_SOURCE[0]}
3+
elif [ -n "${ZSH_VERSION-}" ]; then
4+
eval '_this_file=${(%):-%N}'
5+
else
6+
echo "This script must be sourced from bash or zsh." >&2
7+
return 1 2>/dev/null || exit 1
8+
fi
9+
# Get abspath
10+
_this_dir="$(CDPATH= cd -- "$(dirname -- "$_this_file")" 2>/dev/null && pwd -P)"
11+
12+
case ":$PATH:" in
13+
*":$_this_dir/bin:"*)
14+
# already present: do nothing
15+
# This is an exact match, and e.g. won't match if PATH contains this
16+
# dir with a trailing slash after "bin". That's good enough to avoid
17+
# adding duplicate entries when re-sourcing this, but will add a
18+
# duplicate if the user manually added .../bin/ to their PATH
19+
:
20+
;;
21+
*)
22+
PATH="$_this_dir/bin${PATH+:$PATH}"
23+
export PATH
24+
;;
25+
esac

0 commit comments

Comments
 (0)