summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/spack/spack/cmd/env.py6
-rw-r--r--lib/spack/spack/cmd/load.py3
-rw-r--r--lib/spack/spack/cmd/unload.py3
-rw-r--r--lib/spack/spack/environment.py29
-rw-r--r--lib/spack/spack/util/environment.py2
5 files changed, 41 insertions, 2 deletions
diff --git a/lib/spack/spack/cmd/env.py b/lib/spack/spack/cmd/env.py
index 43c125e8f2..d3e825f1dd 100644
--- a/lib/spack/spack/cmd/env.py
+++ b/lib/spack/spack/cmd/env.py
@@ -52,6 +52,9 @@ def env_activate_setup_parser(subparser):
shells.add_argument(
'--csh', action='store_const', dest='shell', const='csh',
help="print csh commands to activate the environment")
+ shells.add_argument(
+ '--fish', action='store_const', dest='shell', const='fish',
+ help="print fish commands to activate the environment")
view_options = subparser.add_mutually_exclusive_group()
view_options.add_argument(
@@ -127,6 +130,9 @@ def env_deactivate_setup_parser(subparser):
shells.add_argument(
'--csh', action='store_const', dest='shell', const='csh',
help="print csh commands to deactivate the environment")
+ shells.add_argument(
+ '--fish', action='store_const', dest='shell', const='fish',
+ help="print fish commands to activate the environment")
def env_deactivate(args):
diff --git a/lib/spack/spack/cmd/load.py b/lib/spack/spack/cmd/load.py
index 3ef485941f..3938602882 100644
--- a/lib/spack/spack/cmd/load.py
+++ b/lib/spack/spack/cmd/load.py
@@ -32,6 +32,9 @@ def setup_parser(subparser):
shells.add_argument(
'--csh', action='store_const', dest='shell', const='csh',
help="print csh commands to load the package")
+ shells.add_argument(
+ '--fish', action='store_const', dest='shell', const='fish',
+ help="print fish commands to load the package")
subparser.add_argument(
'--first',
diff --git a/lib/spack/spack/cmd/unload.py b/lib/spack/spack/cmd/unload.py
index d19a33102f..cbee2fc769 100644
--- a/lib/spack/spack/cmd/unload.py
+++ b/lib/spack/spack/cmd/unload.py
@@ -31,6 +31,9 @@ def setup_parser(subparser):
shells.add_argument(
'--csh', action='store_const', dest='shell', const='csh',
help="print csh commands to activate the environment")
+ shells.add_argument(
+ '--fish', action='store_const', dest='shell', const='fish',
+ help="print fish commands to load the package")
subparser.add_argument('-a', '--all', action='store_true',
help='unload all loaded Spack packages.')
diff --git a/lib/spack/spack/environment.py b/lib/spack/spack/environment.py
index 32bd8c962d..f7b50c30c9 100644
--- a/lib/spack/spack/environment.py
+++ b/lib/spack/spack/environment.py
@@ -115,7 +115,7 @@ def activate(
use_env_repo (bool): use the packages exactly as they appear in the
environment's repository
add_view (bool): generate commands to add view to path variables
- shell (string): One of `sh`, `csh`.
+ shell (string): One of `sh`, `csh`, `fish`.
prompt (string): string to add to the users prompt, or None
Returns:
@@ -141,6 +141,19 @@ def activate(
cmds += 'if (! $?SPACK_OLD_PROMPT ) '
cmds += 'setenv SPACK_OLD_PROMPT "${prompt}";\n'
cmds += 'set prompt="%s ${prompt}";\n' % prompt
+ elif shell == 'fish':
+ if os.getenv('TERM') and 'color' in os.getenv('TERM') and prompt:
+ prompt = colorize('@G{%s} ' % prompt, color=True)
+
+ cmds += 'set -gx SPACK_ENV %s;\n' % env.path
+ cmds += 'function despacktivate;\n'
+ cmds += ' spack env deactivate;\n'
+ cmds += 'end;\n'
+ #
+ # NOTE: We're not changing the fish_prompt function (which is fish's
+ # solution to the PS1 variable) here. This is a bit fiddly, and easy to
+ # screw up => spend time reasearching a solution. Feedback welcome.
+ #
else:
if os.getenv('TERM') and 'color' in os.getenv('TERM') and prompt:
prompt = colorize('@G{%s} ' % prompt, color=True)
@@ -156,6 +169,12 @@ def activate(
cmds += 'fi;\n'
cmds += 'export PS1="%s ${PS1}";\n' % prompt
+ #
+ # NOTE in the fish-shell: Path variables are a special kind of variable
+ # used to support colon-delimited path lists including PATH, CDPATH,
+ # MANPATH, PYTHONPATH, etc. All variables that end in PATH (case-sensitive)
+ # become PATH variables.
+ #
if add_view and default_view_name in env.views:
with spack.store.db.read_transaction():
cmds += env.add_default_view_to_shell(shell)
@@ -167,7 +186,7 @@ def deactivate(shell='sh'):
"""Undo any configuration or repo settings modified by ``activate()``.
Arguments:
- shell (string): One of `sh`, `csh`. Shell style to use.
+ shell (string): One of `sh`, `csh`, `fish`. Shell style to use.
Returns:
(string): shell commands for `shell` to undo environment variables
@@ -191,6 +210,12 @@ def deactivate(shell='sh'):
cmds += 'set prompt="$SPACK_OLD_PROMPT" && '
cmds += 'unsetenv SPACK_OLD_PROMPT;\n'
cmds += 'unalias despacktivate;\n'
+ elif shell == 'fish':
+ cmds += 'set -e SPACK_ENV;\n'
+ cmds += 'functions -e despacktivate;\n'
+ #
+ # NOTE: Not changing fish_prompt (above) => no need to restore it here.
+ #
else:
cmds += 'if [ ! -z ${SPACK_ENV+x} ]; then\n'
cmds += 'unset SPACK_ENV; export SPACK_ENV;\n'
diff --git a/lib/spack/spack/util/environment.py b/lib/spack/spack/util/environment.py
index 3d69efa5ca..7e6d34e64d 100644
--- a/lib/spack/spack/util/environment.py
+++ b/lib/spack/spack/util/environment.py
@@ -32,12 +32,14 @@ system_dirs = [os.path.join(p, s) for s in suffixes for p in system_paths] + \
_shell_set_strings = {
'sh': 'export {0}={1};\n',
'csh': 'setenv {0} {1};\n',
+ 'fish': 'set -gx {0} {1};\n'
}
_shell_unset_strings = {
'sh': 'unset {0};\n',
'csh': 'unsetenv {0};\n',
+ 'fish': 'set -e {0};\n',
}