diff --git a/libmamba/src/core/shell_init.cpp b/libmamba/src/core/shell_init.cpp index 1f908d9bf..d823eed72 100644 --- a/libmamba/src/core/shell_init.cpp +++ b/libmamba/src/core/shell_init.cpp @@ -97,6 +97,14 @@ namespace mamba { return "fish"; } + + // Get `SHELL` environment variable if set + // Standard values are assumed to be `/bin/{shell_type}` or `/usr/bin/{shell_type}` + if (util::get_env("SHELL").has_value()) + { + return util::split(util::get_env("SHELL").value(), "/").back(); + } + return ""; } diff --git a/libmamba/tests/src/util/test_string.cpp b/libmamba/tests/src/util/test_string.cpp index f1bd26a4f..6ebd9dc13 100644 --- a/libmamba/tests/src/util/test_string.cpp +++ b/libmamba/tests/src/util/test_string.cpp @@ -460,6 +460,10 @@ namespace std::vector v21 = { "conda-forge/linux64:", "xtensor==0.12.3" }; REQUIRE(rsplit("conda-forge/linux64::xtensor==0.12.3", ":", 1) == v21); + + std::vector es3 = { "" }; + REQUIRE(split(es3[0], ".") == es3); + REQUIRE(rsplit(es3[0], ".") == es3); } TEST_CASE("join") diff --git a/micromamba/tests/test_shell.py b/micromamba/tests/test_shell.py index 01cae7384..24c46b434 100644 --- a/micromamba/tests/test_shell.py +++ b/micromamba/tests/test_shell.py @@ -225,6 +225,14 @@ def test_init(tmp_home, tmp_root_prefix, shell_type, prefix_selector, multiple_t assert (tmp_root_prefix / "condabin").is_dir() +def test_shell_init_with_env_var(tmp_home, tmp_root_prefix): + skip_if_shell_incompat("bash") + umamba_cmd = helpers.get_umamba() + res = helpers.umamba_run("sh", "-c", f"export SHELL=/bin/bash; {umamba_cmd} shell init") + assert res + assert (tmp_root_prefix / "etc" / "profile.d").is_dir() + + def test_dash(tmp_home, tmp_root_prefix): skip_if_shell_incompat("dash") umamba = helpers.get_umamba()