Add fish shell support (#9279)
* share/spack/setup-env.fish file to setup environment in fish shell * setup-env.fish testing script * Update share/spack/setup-env.fish Co-Authored-By: Elsa Gonsiorowski, PhD <gonsie@me.com> * Update share/spack/qa/setup-env-test.fish Co-Authored-By: Adam J. Stewart <ajstewart426@gmail.com> * updates completions using `spack commands --update-completion` * added stderr-nocaret warning * added fish shell tests to CI system Co-authored-by: becker33 <becker33@llnl.gov> Co-authored-by: Adam J. Stewart <ajstewart426@gmail.com> Co-authored-by: Elsa Gonsiorowski, PhD <gonsie@me.com>
This commit is contained in:

committed by
GitHub

parent
212299a021
commit
1d55adfd2b
@@ -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):
|
||||
|
@@ -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',
|
||||
|
@@ -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.')
|
||||
|
@@ -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'
|
||||
|
@@ -32,12 +32,14 @@
|
||||
_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',
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user