Skip to content

feat: Use ZDOTDIR if set and fallback to HOME#3933

Open
ickc wants to merge 5 commits intomamba-org:mainfrom
ickc:zsh
Open

feat: Use ZDOTDIR if set and fallback to HOME#3933
ickc wants to merge 5 commits intomamba-org:mainfrom
ickc:zsh

Conversation

@ickc
Copy link
Copy Markdown
Contributor

@ickc ickc commented May 12, 2025

No description provided.

Comment thread libmamba/src/core/shell_init.cpp Outdated
fs::u8path zshrc_path = home / ".zshrc";
fs::u8path zshrc_path
// use ZDOTDIR if set and fallback to HOME
const char* zdotdir = std::getenv("ZDOTDIR");
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have util::get_env to properly read from the environment.

Comment thread libmamba/src/core/shell_init.cpp Outdated
Comment on lines +1360 to +1368
fs::u8path zshrc_path
// use ZDOTDIR if set and fallback to HOME
const char* zdotdir = std::getenv("ZDOTDIR");
if (zdotdir != nullptr && zdotdir[0] != '\0')
{
zshrc_path = fs::u8path(zdotdir) / ".zshrc";
} else {
zshrc_path = home / ".zshrc";
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like the repeated logic could be factored into a simple function.

@codecov
Copy link
Copy Markdown

codecov Bot commented Sep 25, 2025

Codecov Report

❌ Patch coverage is 57.14286% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 50.84%. Comparing base (59f22ac) to head (55eaaf7).

Files with missing lines Patch % Lines
libmamba/src/core/shell_init.cpp 0.00% 3 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3933   +/-   ##
=======================================
  Coverage   50.83%   50.84%           
=======================================
  Files         237      237           
  Lines       28228    28235    +7     
  Branches     2919     2920    +1     
=======================================
+ Hits        14351    14356    +5     
- Misses      13874    13876    +2     
  Partials        3        3           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@AntoinePrv AntoinePrv changed the title use ZDOTDIR if set and fallback to HOME feat: Use ZDOTDIR if set and fallback to HOME Sep 25, 2025
@github-actions github-actions Bot added the release::enhancements For enhancements PRs or implementing features label Sep 25, 2025
@ickc ickc force-pushed the zsh branch 2 times, most recently from 3b7b065 to 0ea3710 Compare September 25, 2025 16:15
@ickc
Copy link
Copy Markdown
Contributor Author

ickc commented Sep 25, 2025

@AntoinePrv, do you have any pointers to fix the windows build and also the integration tests on UNIX platforms?

@ickc ickc marked this pull request as ready for review February 5, 2026 12:58
Copilot AI review requested due to automatic review settings February 5, 2026 12:58
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds support for the ZDOTDIR environment variable in zsh shell initialization, allowing users to specify a custom location for zsh configuration files. If ZDOTDIR is not set, the code falls back to the user's home directory, which is the standard zsh behavior.

Changes:

  • Added zsh_home_dir() function to check ZDOTDIR environment variable and fall back to HOME
  • Updated zsh shell initialization code to use zsh_home_dir() instead of user_home_dir()
  • Added test coverage for the new zsh_home_dir() function

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

File Description
libmamba/include/mamba/util/environment.hpp Declares zsh_home_dir() function with platform guard for non-Windows systems
libmamba/src/util/environment.cpp Implements zsh_home_dir() to check ZDOTDIR and fallback to user_home_dir()
libmamba/src/core/shell_init.cpp Updates three functions (init_shell, deinit_shell, config_path_for_shell) to use zsh_home_dir() for zsh configuration
libmamba/tests/src/util/test_environment.cpp Adds test cases for zsh_home_dir() covering both ZDOTDIR set and not set scenarios

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 1284 to 1290
}
else if (shell == "zsh")
{
home = util::zsh_home_dir();
fs::u8path zshrc_path = home / ".zshrc";
modify_rc_file(context, zshrc_path, conda_prefix, shell, mamba_exe);
}
Copy link

Copilot AI Feb 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function util::zsh_home_dir() is only declared for non-Windows platforms (guarded by #ifndef _WIN32 in the header file), but it's being called here without platform guards. This will cause a compilation error on Windows. The call should be wrapped in #ifndef _WIN32 preprocessor guards, or the entire zsh block should be conditionally compiled for non-Windows platforms only.

Suggested change
}
else if (shell == "zsh")
{
home = util::zsh_home_dir();
fs::u8path zshrc_path = home / ".zshrc";
modify_rc_file(context, zshrc_path, conda_prefix, shell, mamba_exe);
}
}
#ifndef _WIN32
else if (shell == "zsh")
{
home = util::zsh_home_dir();
fs::u8path zshrc_path = home / ".zshrc";
modify_rc_file(context, zshrc_path, conda_prefix, shell, mamba_exe);
}
#endif

Copilot uses AI. Check for mistakes.
Comment on lines 1361 to +1362
{
home = util::zsh_home_dir();
Copy link

Copilot AI Feb 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function util::zsh_home_dir() is only declared for non-Windows platforms (guarded by #ifndef _WIN32 in the header file), but it's being called here without platform guards. This will cause a compilation error on Windows. The call should be wrapped in #ifndef _WIN32 preprocessor guards, or the entire zsh block should be conditionally compiled for non-Windows platforms only.

Suggested change
{
home = util::zsh_home_dir();
{
#ifndef _WIN32
home = util::zsh_home_dir();
#endif

Copilot uses AI. Check for mistakes.
Comment on lines 1428 to +1429
{
home = util::zsh_home_dir();
Copy link

Copilot AI Feb 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function util::zsh_home_dir() is only declared for non-Windows platforms (guarded by #ifndef _WIN32 in the header file), but it's being called here without platform guards. This will cause a compilation error on Windows. The call should be wrapped in #ifndef _WIN32 preprocessor guards, or the entire zsh block should be conditionally compiled for non-Windows platforms only.

Suggested change
{
home = util::zsh_home_dir();
{
#ifndef _WIN32
home = util::zsh_home_dir();
#endif

Copilot uses AI. Check for mistakes.
Comment on lines +169 to +190
TEST_CASE("zsh_home_dir", "[mamba::util]")
{
if (on_win)
{
return;
}

const auto restore = mambatests::EnvironmentCleaner();

SECTION("ZDOTDIR set")
{
set_env("ZDOTDIR", "/user/mamba/.zsh");
REQUIRE(zsh_home_dir() == "/user/mamba/.zsh");
}

SECTION("ZDOTDIR not set")
{
unset_env("ZDOTDIR");
set_env("HOME", "/user/mamba");
REQUIRE(zsh_home_dir() == user_home_dir());
}
}
Copy link

Copilot AI Feb 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test case calls zsh_home_dir() which is only declared for non-Windows platforms (guarded by #ifndef _WIN32 in the header file). While there's a runtime check if (on_win) { return; } to skip the test on Windows, the test will still fail to compile on Windows because the compiler sees the calls to zsh_home_dir() regardless of the runtime check. The entire test case should be wrapped in #ifndef _WIN32 preprocessor guards to prevent compilation errors on Windows.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release::enhancements For enhancements PRs or implementing features

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants