summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTodd Gamblin <tgamblin@llnl.gov>2020-10-21 17:04:42 -0700
committerGitHub <noreply@github.com>2020-10-21 17:04:42 -0700
commit16e75ecac097450b2abee7ea0644929b97e45bd7 (patch)
tree67ab597d6cdf04ee32b0bda435950f759c53e8d4
parent93e7267dcce46515e61287bfe932e2e5854ef454 (diff)
downloadspack-16e75ecac097450b2abee7ea0644929b97e45bd7.tar.gz
spack-16e75ecac097450b2abee7ea0644929b97e45bd7.tar.bz2
spack-16e75ecac097450b2abee7ea0644929b97e45bd7.tar.xz
spack-16e75ecac097450b2abee7ea0644929b97e45bd7.zip
shell support: make `which spack` output intelligible (#19256)
Zsh and newer versions of bash have a builtin `which` function that will show you if a command is actually an alias or a function. For functions, the entire function is printed, and our `spack()` function is quite long. Instead of printing out all that, make the `spack()` function a wrapper around `_spack_shell_wrapper()`, and include some no-ops in the definition so that users can see where it was created and where Spack is installed. Here's what the new output looks like in zsh: ```console $ which spack spack () { : this is a shell function from: /Users/gamblin2/src/spack/share/spack/setup-env.sh : the real spack script is here: /Users/gamblin2/src/spack/bin/spack _spack "$@" return $? } ``` Note that `:` is a no-op in Bourne shell; it just discards anything after it on the line. We use it here to embed paths in the function definition (as comments are stripped).
-rwxr-xr-xshare/spack/setup-env.sh23
1 files changed, 17 insertions, 6 deletions
diff --git a/share/spack/setup-env.sh b/share/spack/setup-env.sh
index 9d984ae199..5761d16362 100755
--- a/share/spack/setup-env.sh
+++ b/share/spack/setup-env.sh
@@ -45,7 +45,8 @@ if [ -n "${_sp_initializing:-}" ]; then
fi
export _sp_initializing=true
-spack() {
+
+_spack_shell_wrapper() {
# Store LD_LIBRARY_PATH variables from spack shell function
# This is necessary because MacOS System Integrity Protection clears
# variables that affect dyld on process start.
@@ -243,11 +244,6 @@ _spack_determine_shell() {
_sp_shell=$(_spack_determine_shell)
-# Export spack function so it is available in subshells (only works with bash)
-if [ "$_sp_shell" = bash ]; then
- export -f spack
-fi
-
alias spacktivate="spack env activate"
#
@@ -315,6 +311,21 @@ if ! _spack_fn_exists use && ! _spack_fn_exists module; then
need_module="yes"
fi;
+# Define the spack shell function with some informative no-ops, so when users
+# run `which spack`, they see the path to spack and where the function is from.
+eval "spack() {
+ : this is a shell function from: $_sp_share_dir/setup-env.sh
+ : the real spack script is here: $_sp_prefix/bin/spack
+ _spack_shell_wrapper \"\$@\"
+ return \$?
+}"
+
+# Export spack function so it is available in subshells (only works with bash)
+if [ "$_sp_shell" = bash ]; then
+ export -f spack
+ export -f _spack_shell_wrapper
+fi
+
#
# make available environment-modules
#