Skip to content

Commit

Permalink
Working nushell implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
cvanelteren committed Jul 31, 2023
1 parent b3cc923 commit a76cc6e
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 37 deletions.
2 changes: 1 addition & 1 deletion libmamba/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ set(SHELL_SCRIPTS
Mamba.psm1
mamba.xsh
mamba.fish
mamba.nu
micromamba.nu
compile_pyc.py
mamba_completion.posix
)
Expand Down
16 changes: 0 additions & 16 deletions libmamba/data/mamba.nu

This file was deleted.

31 changes: 31 additions & 0 deletions libmamba/data/micromamba.nu
Original file line number Diff line number Diff line change
@@ -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 = ""
}
}
1 change: 0 additions & 1 deletion libmamba/include/mamba/core/shell_init.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
2 changes: 1 addition & 1 deletion libmamba/src/core/activation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string, std::string>
Expand Down
13 changes: 7 additions & 6 deletions libmamba/src/core/shell_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.string() << "/etc/profile.d/micromamba.nu\n";
content << "# <<< mamba initialize <<<\n";
return content.str();
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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")
{
Expand Down
2 changes: 1 addition & 1 deletion mamba/mamba/mamba_shell_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 0 additions & 9 deletions mamba/mamba/shell_templates/mamba.nu

This file was deleted.

2 changes: 1 addition & 1 deletion mamba/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]),
]
Expand Down
2 changes: 1 addition & 1 deletion micromamba/tests/test_activation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}")

Expand Down

0 comments on commit a76cc6e

Please sign in to comment.