Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for mamba init fish #2006

Merged
merged 1 commit into from
Oct 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 23 additions & 13 deletions mamba/mamba/mamba_shell_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,15 @@
SHELL_TEMPLATES = join(HERE, "shell_templates")

MAMBA_SNIPPET_SH = """
if [ -f "{mamba_sh_path}" ]; then
. "{mamba_sh_path}"
if [ -f "{mamba_source_path}" ]; then
. "{mamba_source_path}"
fi
"""
MAMBA_SNIPPET_FISH = """
if test -f "{mamba_source_path}"
source "{mamba_source_path}"
end
"""


def add_mamba_to_rcfile(file, conda_prefix):
Expand All @@ -30,14 +35,21 @@ def check_init_block(lines, start_i, prefix):
with open(file, "r") as fi:
current_content = fi.readlines()

mamba_sh_path = native_path_to_unix(
join(conda_prefix, "etc", "profile.d", "mamba.sh")
)
if file.endswith(".fish"):
snippet = MAMBA_SNIPPET_FISH
mamba_source_path = native_path_to_unix(
join(conda_prefix, "etc", "fish", "conf.d", "mamba.fish")
)
else:
snippet = MAMBA_SNIPPET_SH
mamba_source_path = native_path_to_unix(
join(conda_prefix, "etc", "profile.d", "mamba.sh")
)
new_content = []
for i, line in enumerate(current_content):
if line.startswith("# <<< conda initialize <<<"):
if check_init_block(current_content, i, native_path_to_unix(conda_prefix)):
new_content.append(MAMBA_SNIPPET_SH.format(mamba_sh_path=mamba_sh_path))
new_content.append(snippet.format(mamba_source_path=mamba_source_path))
new_content.append(line)

with open(file, "w") as fo:
Expand Down Expand Up @@ -96,13 +108,11 @@ def shell_init(args):
args.reverse,
)
for el in plan:
if el.get("function") == "init_sh_user":
dlukes marked this conversation as resolved.
Show resolved Hide resolved
args = el.get("kwargs")
target_path = args["target_path"]
conda_prefix = args["conda_prefix"]
add_mamba_to_rcfile(target_path, conda_prefix)
changed = True
if el.get("function") == "init_sh_system":
if el.get("function") in (
"init_sh_user",
"init_sh_system",
"init_fish_user",
):
args = el.get("kwargs")
target_path = args["target_path"]
conda_prefix = args["conda_prefix"]
Expand Down
24 changes: 24 additions & 0 deletions mamba/mamba/shell_templates/mamba.fish
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Based on conda.fish which is licensed as below
#
# Copyright (C) 2012 Anaconda, Inc
# SPDX-License-Identifier: BSD-3-Clause

set -gx MAMBA_EXE (dirname $CONDA_EXE)/mamba
dlukes marked this conversation as resolved.
Show resolved Hide resolved

function mamba --inherit-variable CONDA_EXE --inherit-variable MAMBA_EXE
if test (count $argv) -lt 1 || contains -- --help $argv
$MAMBA_EXE $argv
else
set -l cmd $argv[1]
set -e argv[1]
switch $cmd
case activate deactivate
eval ($CONDA_EXE shell -s fish $cmd $argv)
case install update upgrade remove uninstall
$MAMBA_EXE $cmd $argv || return $status
and eval ($CONDA_EXE shell -s fish reactivate)
case '*'
$MAMBA_EXE $cmd $argv
end
end
end
1 change: 1 addition & 0 deletions mamba/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

data_files = [
("etc/profile.d", ["mamba/shell_templates/mamba.sh"]),
("etc/fish/conf.d", ["mamba/shell_templates/mamba.fish"]),
dlukes marked this conversation as resolved.
Show resolved Hide resolved
]
if sys.platform == "win32":
data_files.append(
Expand Down