Skip to content

Commit 322ec1e

Browse files
ickcAntoinePrv
authored andcommitted
use ZDOTDIR if set and fallback to HOME
1 parent 2ee50e0 commit 322ec1e

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
@@ -1275,7 +1275,15 @@ namespace mamba
12751275
}
12761276
else if (shell == "zsh")
12771277
{
1278-
fs::u8path zshrc_path = home / ".zshrc";
1278+
fs::u8path zshrc_path
1279+
// use ZDOTDIR if set and fallback to HOME
1280+
const char* zdotdir = std::getenv("ZDOTDIR");
1281+
if (zdotdir != nullptr && zdotdir[0] != '\0')
1282+
{
1283+
zshrc_path = fs::u8path(zdotdir) / ".zshrc";
1284+
} else {
1285+
zshrc_path = home / ".zshrc";
1286+
}
12791287
modify_rc_file(context, zshrc_path, conda_prefix, shell, mamba_exe);
12801288
}
12811289
else if (shell == "csh")
@@ -1349,7 +1357,15 @@ namespace mamba
13491357
}
13501358
else if (shell == "zsh")
13511359
{
1352-
fs::u8path zshrc_path = home / ".zshrc";
1360+
fs::u8path zshrc_path
1361+
// use ZDOTDIR if set and fallback to HOME
1362+
const char* zdotdir = std::getenv("ZDOTDIR");
1363+
if (zdotdir != nullptr && zdotdir[0] != '\0')
1364+
{
1365+
zshrc_path = fs::u8path(zdotdir) / ".zshrc";
1366+
} else {
1367+
zshrc_path = home / ".zshrc";
1368+
}
13531369
reset_rc_file(context, zshrc_path, shell, mamba_exe);
13541370
}
13551371
else if (shell == "xonsh")
@@ -1415,7 +1431,14 @@ namespace mamba
14151431
}
14161432
else if (shell == "zsh")
14171433
{
1418-
config_path = home / ".zshrc";
1434+
// use ZDOTDIR if set and fallback to HOME
1435+
const char* zdotdir = std::getenv("ZDOTDIR");
1436+
if (zdotdir != nullptr && zdotdir[0] != '\0')
1437+
{
1438+
config_path = fs::u8path(zdotdir) / ".zshrc";
1439+
} else {
1440+
config_path = home / ".zshrc";
1441+
}
14191442
}
14201443
else if (shell == "xonsh")
14211444
{

0 commit comments

Comments
 (0)