summaryrefslogtreecommitdiff
path: root/share/spack/setup-env.sh
diff options
context:
space:
mode:
authorTodd Gamblin <tgamblin@llnl.gov>2018-10-14 15:21:57 -0700
committerTodd Gamblin <tgamblin@llnl.gov>2018-11-09 00:31:24 -0800
commitd14f7b82bb0435053a94ae26fd597767d151f8a9 (patch)
tree4736d20cf3875e88dbf6cde96ba1935e48f32ab8 /share/spack/setup-env.sh
parent15c5c36eafa41aca9267581b1e00fdce67cc4b36 (diff)
downloadspack-d14f7b82bb0435053a94ae26fd597767d151f8a9.tar.gz
spack-d14f7b82bb0435053a94ae26fd597767d151f8a9.tar.bz2
spack-d14f7b82bb0435053a94ae26fd597767d151f8a9.tar.xz
spack-d14f7b82bb0435053a94ae26fd597767d151f8a9.zip
env: add spack env activate/deactivate and shell support
- `spack env activate foo`: sets SPACK_ENV to the current active env name - `spack env deactivate`: unsets SPACK_ENV, deactivates the environment - added support to setup_env.sh and setup_env.csh - other env commands work properly with SPACK_ENV, as with an environment arguments. - command-line --env arguments take precedence over the active environment, if given.
Diffstat (limited to 'share/spack/setup-env.sh')
-rwxr-xr-xshare/spack/setup-env.sh36
1 files changed, 36 insertions, 0 deletions
diff --git a/share/spack/setup-env.sh b/share/spack/setup-env.sh
index 9f2bb2618c..af18fcd4e1 100755
--- a/share/spack/setup-env.sh
+++ b/share/spack/setup-env.sh
@@ -89,6 +89,42 @@ function spack {
fi
return
;;
+ "env")
+ _sp_arg=""
+ if [ -n "$1" ]; then
+ _sp_arg="$1"
+ shift
+ fi
+
+ if [ "$_sp_arg" = "-h" ]; then
+ command spack env -h
+ else
+ case $_sp_arg in
+ activate)
+ if [ -z "$1" -o "${1#-}" != "$1" ]; then
+ # no args or does not start with -: just execute
+ command spack "${args[@]}"
+ else
+ # actual call to activate: source the output
+ eval $(command spack $_sp_flags env activate --sh "$@")
+ fi
+ ;;
+ deactivate)
+ if [ -n "$1" ]; then
+ # with args: execute the command
+ command spack "${args[@]}"
+ else
+ # no args: source the output.
+ eval $(command spack $_sp_flags env deactivate --sh)
+ fi
+ ;;
+ *)
+ command spack "${args[@]}"
+ ;;
+ esac
+ fi
+ return
+ ;;
"use"|"unuse"|"load"|"unload")
# Shift any other args for use off before parsing spec.
_sp_subcommand_args=""