Skip to content

Commit e39196d

Browse files
authored
Consider SHELL env var (#3997)
1 parent b3d580e commit e39196d

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

libmamba/src/core/shell_init.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,14 @@ namespace mamba
9797
{
9898
return "fish";
9999
}
100+
101+
// Get `SHELL` environment variable if set
102+
// Standard values are assumed to be `/bin/{shell_type}` or `/usr/bin/{shell_type}`
103+
if (util::get_env("SHELL").has_value())
104+
{
105+
return util::split(util::get_env("SHELL").value(), "/").back();
106+
}
107+
100108
return "";
101109
}
102110

libmamba/tests/src/util/test_string.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,10 @@ namespace
460460
std::vector<std::string> v21 = { "conda-forge/linux64:", "xtensor==0.12.3" };
461461

462462
REQUIRE(rsplit("conda-forge/linux64::xtensor==0.12.3", ":", 1) == v21);
463+
464+
std::vector<std::string> es3 = { "" };
465+
REQUIRE(split(es3[0], ".") == es3);
466+
REQUIRE(rsplit(es3[0], ".") == es3);
463467
}
464468

465469
TEST_CASE("join")

micromamba/tests/test_shell.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,14 @@ def test_init(tmp_home, tmp_root_prefix, shell_type, prefix_selector, multiple_t
225225
assert (tmp_root_prefix / "condabin").is_dir()
226226

227227

228+
def test_shell_init_with_env_var(tmp_home, tmp_root_prefix):
229+
skip_if_shell_incompat("bash")
230+
umamba_cmd = helpers.get_umamba()
231+
res = helpers.umamba_run("sh", "-c", f"export SHELL=/bin/bash; {umamba_cmd} shell init")
232+
assert res
233+
assert (tmp_root_prefix / "etc" / "profile.d").is_dir()
234+
235+
228236
def test_dash(tmp_home, tmp_root_prefix):
229237
skip_if_shell_incompat("dash")
230238
umamba = helpers.get_umamba()

0 commit comments

Comments
 (0)