Skip to content

Commit fbbee9f

Browse files
committed
use ZDOTDIR if set and fallback to HOME
1 parent 9ad464b commit fbbee9f

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed

libmamba/src/core/shell_init.cpp

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1274,7 +1274,15 @@ namespace mamba
12741274
}
12751275
else if (shell == "zsh")
12761276
{
1277-
fs::u8path zshrc_path = home / ".zshrc";
1277+
fs::u8path zshrc_path
1278+
// use ZDOTDIR if set and fallback to HOME
1279+
const char* zdotdir = std::getenv("ZDOTDIR");
1280+
if (zdotdir != nullptr && zdotdir[0] != '\0')
1281+
{
1282+
zshrc_path = fs::u8path(zdotdir) / ".zshrc";
1283+
} else {
1284+
zshrc_path = home / ".zshrc";
1285+
}
12781286
modify_rc_file(context, zshrc_path, conda_prefix, shell, mamba_exe);
12791287
}
12801288
else if (shell == "csh")
@@ -1348,7 +1356,15 @@ namespace mamba
13481356
}
13491357
else if (shell == "zsh")
13501358
{
1351-
fs::u8path zshrc_path = home / ".zshrc";
1359+
fs::u8path zshrc_path
1360+
// use ZDOTDIR if set and fallback to HOME
1361+
const char* zdotdir = std::getenv("ZDOTDIR");
1362+
if (zdotdir != nullptr && zdotdir[0] != '\0')
1363+
{
1364+
zshrc_path = fs::u8path(zdotdir) / ".zshrc";
1365+
} else {
1366+
zshrc_path = home / ".zshrc";
1367+
}
13521368
reset_rc_file(context, zshrc_path, shell, mamba_exe);
13531369
}
13541370
else if (shell == "xonsh")
@@ -1414,7 +1430,14 @@ namespace mamba
14141430
}
14151431
else if (shell == "zsh")
14161432
{
1417-
config_path = home / ".zshrc";
1433+
// use ZDOTDIR if set and fallback to HOME
1434+
const char* zdotdir = std::getenv("ZDOTDIR");
1435+
if (zdotdir != nullptr && zdotdir[0] != '\0')
1436+
{
1437+
config_path = fs::u8path(zdotdir) / ".zshrc";
1438+
} else {
1439+
config_path = home / ".zshrc";
1440+
}
14181441
}
14191442
else if (shell == "xonsh")
14201443
{

0 commit comments

Comments
 (0)