diff --git a/libmamba/CMakeLists.txt b/libmamba/CMakeLists.txt index 94d6d9f7b1..5d0f22a2b2 100644 --- a/libmamba/CMakeLists.txt +++ b/libmamba/CMakeLists.txt @@ -100,7 +100,7 @@ set(SHELL_SCRIPTS Mamba.psm1 mamba.xsh mamba.fish - mamba.nu + micromamba.nu compile_pyc.py mamba_completion.posix ) diff --git a/libmamba/data/mamba.nu b/libmamba/data/mamba.nu deleted file mode 100644 index 043dc48fed..0000000000 --- a/libmamba/data/mamba.nu +++ /dev/null @@ -1,16 +0,0 @@ -#!/usr/bin/env nu -def-env micromamba [...cmd] { - let reactivate = [update upgrade remove uninstall] - if ($cmd.0 in reactivate) { - run-external $env.MAMBA_EXE $cmd; - run-external $env.MAMBA_EXE reactivate; - } - else { - run-external $env.MAMBA_EXE $cmd; - } -} - -if ( $env.MAMBA_SHLVL? == null ) { - $env.MAMBA_SHLVL = 0 - $env.PATH = ( $env.PATH | append ([ $env.MAMBA_ROOT_PREFIX condabin] | path join )) -} diff --git a/libmamba/data/micromamba.nu b/libmamba/data/micromamba.nu new file mode 100644 index 0000000000..59e6dae88d --- /dev/null +++ b/libmamba/data/micromamba.nu @@ -0,0 +1,31 @@ +#!/usr/bin/env nu +def-env "micromamba activate" [name: string] { + # get envs and update current env to path + let envs = ( + (micromamba env list --json | from json).envs | reduce -f {} {|it, acc| + $acc | upsert ($it | path basename) $it + } + ) + + # fetch path of current environment and update if present + let env_path = ($envs | get $name) + let p = ([$env_path "bin"] | path join) + if not $p in $env.PATH { + $env.PATH = ($env.PATH | prepend $p) + $env.MICROMAMBA_CURRENT_ENV = $name + } +} + +def-env "micromamba deactivate" [] { + # get envs and unset current env + let envs = ( + (micromamba env list --json | from json).envs | reduce -f {} {|it, acc| + $acc | upsert ($it | path basename) $it + } + ) + if $env.MICROMAMBA_CURRENT_ENV in $envs { + let path = ([($envs | get $env.MICROMAMBA_CURRENT_ENV) "bin"] | path join) + $env.PATH = ($env.PATH | filter {|it| $it != $path}) + $env.MICROMAMBA_CURRENT_ENV = "" + } +} diff --git a/libmamba/include/mamba/core/shell_init.hpp b/libmamba/include/mamba/core/shell_init.hpp index 0226517dac..a5fbe126d2 100644 --- a/libmamba/include/mamba/core/shell_init.hpp +++ b/libmamba/include/mamba/core/shell_init.hpp @@ -24,7 +24,6 @@ extern const char data_Mamba_psm1[]; extern const char data_mamba_xsh[]; extern const char data_mamba_fish[]; extern const char data_mamba_completion_posix[]; -extern const char data_mamba_nu[]; namespace mamba { diff --git a/libmamba/src/core/activation.cpp b/libmamba/src/core/activation.cpp index 3f118d9723..cd8bbde8b7 100644 --- a/libmamba/src/core/activation.cpp +++ b/libmamba/src/core/activation.cpp @@ -1270,7 +1270,7 @@ namespace mamba // TODO: check this fs::u8path NuActivator::hook_source_path() { - return Context::instance().prefix_params.root_prefix / "etc" / "profile.d" / "mamba.nu"; + return Context::instance().prefix_params.root_prefix / "etc" / "profile.d" / "micromamba.nu"; } std::pair diff --git a/libmamba/src/core/shell_init.cpp b/libmamba/src/core/shell_init.cpp index 806c37afbb..2ffea700c5 100644 --- a/libmamba/src/core/shell_init.cpp +++ b/libmamba/src/core/shell_init.cpp @@ -407,10 +407,11 @@ namespace mamba content << "\n# >>> mamba initialize >>>\n"; content << "# !! Contents within this block are managed by 'mamba init' !!\n"; - content << "$env.MAMBA_EXE = " << mamba_exe << "\n"; - content << "$env.MAMBA_ROOT_PREFIX = " << env_prefix << "\n"; - content << "run-external $env.MAMBA_EXE 'shell' 'hook' '--shell' 'nu' '--root-prefix' $env.MAMBA_ROOT_PREFIX --redirect-stdout \n"; - content << "$env.PATH = ($env.PATH | append ( [$env.MAMBA_ROOT_PREFIX bin] | path join)) \n"; + content << "$env.MICROMAMBA_MAMBA_EXE = " << mamba_exe << "\n"; + content << "$env.MICROMAMBA_ROOT_PREFIX = " << env_prefix << "\n"; + content << "$env.MICROMAMBA_CURRENT_ENV = \"\"\n"; + content << "$env.PATH = ($env.PATH | append ([$env.MICROMAMBA_ROOT_PREFIX bin] | path join) | uniq)\n"; + content << "source " << env_prefix << "/etc/profile.d/micromamba.nu\n"; content << "# <<< mamba initialize <<<\n"; return content.str(); } @@ -612,7 +613,7 @@ namespace mamba // deprecated according to https://github.com/mamba-org/mamba/pull/2693 else if (shell == "nu") { - std::string contents = data_mamba_nu; + std::string contents = data_micromamba_nu; replace_all(contents, "$MAMBA_EXE", exe.string()); return contents; } @@ -809,7 +810,7 @@ namespace mamba { } std::ofstream sh_file = open_ofstream(sh_source_path); - sh_file << data_mamba_nu; + sh_file << data_micromamba_nu; } else if (shell == "cmd.exe") { diff --git a/mamba/mamba/mamba_shell_init.py b/mamba/mamba/mamba_shell_init.py index 96e5444615..8b15a63e3c 100644 --- a/mamba/mamba/mamba_shell_init.py +++ b/mamba/mamba/mamba_shell_init.py @@ -49,7 +49,7 @@ def check_init_block(lines, start_i, prefix): elif file.endswith(".nu"): snippet = MAMBA_SNIPPET_NU mamba_source_path = native_path_to_unix( - join(conda_prefix, "etc", "profile.d", "mamba.nu") + join(conda_prefix, "etc", "profile.d", "micromamba.nu") ) else: snippet = MAMBA_SNIPPET_SH diff --git a/mamba/mamba/shell_templates/mamba.nu b/mamba/mamba/shell_templates/mamba.nu deleted file mode 100644 index 96c123291f..0000000000 --- a/mamba/mamba/shell_templates/mamba.nu +++ /dev/null @@ -1,9 +0,0 @@ -export def mamba [arg] { - if ($arg in [ activate deactivate] ) { - conda $arg; - } - else { - mamba $arg; - } -}; - diff --git a/mamba/setup.py b/mamba/setup.py index dc00505a1a..a7a40a9669 100644 --- a/mamba/setup.py +++ b/mamba/setup.py @@ -22,7 +22,7 @@ data_files = [ ( "etc/profile.d", - ["mamba/shell_templates/mamba.sh", "mamba/shell_templates/mamba.nu"], + ["mamba/shell_templates/mamba.sh", "mamba/shell_templates/micromamba.nu"], ), ("etc/fish/conf.d", ["mamba/shell_templates/mamba.fish"]), ] diff --git a/micromamba/tests/test_activation.py b/micromamba/tests/test_activation.py index fd72f2b2ea..492646c735 100644 --- a/micromamba/tests/test_activation.py +++ b/micromamba/tests/test_activation.py @@ -450,7 +450,7 @@ def test_shell_init_deinit_root_prefix_files( elif interpreter in ["csh", "tcsh"]: files = [tmp_root_prefix / "etc" / "profile.d" / "micromamba.csh"] elif interpreter == "nu": - files = [tmp_root_prefix / "etc" / "profile.d" / "mamba.nu"] + files = [tmp_root_prefix / "etc" / "profile.d" / "micromamba.nu"] else: raise ValueError(f"Unknown shell {interpreter}")