Repository navigation
feat(config): RLEDGER_CONFIG env var + macOS XDG config fallback (#1616) - #1650
Merged
Merged
Conversation
Cross-platform config-location gap reported in discussion #1616: rledger resolves its user config via dirs::config_dir() (platform-native), which is ~/.config on Linux but ~/Library/Application Support on macOS — and dirs ignores XDG_CONFIG_HOME on macOS. So a single ~/.config/rledger/config.toml managed by chezmoi/home-manager couldn't work on both, and there was no env override. user_config_path() now resolves in this order: 1. $RLEDGER_CONFIG — explicit config file path (~ and $VAR expanded); highest precedence, ideal for cross-platform dotfile managers. 2. The platform-native dirs::config_dir()/rledger/config.toml. 3. macOS only: $XDG_CONFIG_HOME / ~/.config/rledger/config.toml when present, so an XDG-style dotfile works on macOS too without any env var. The override resolution is a pure, unit-tested helper (resolve_user_config_path); the env-var help (config_cmd) documents RLEDGER_CONFIG. Addresses discussion #1616. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a cross-platform override and fallback strategy for locating rledger’s user config, addressing macOS’s non-XDG default config directory behavior and enabling a single canonical config path for dotfile managers.
Changes:
- Add
$RLEDGER_CONFIGas the highest-precedence override for the user config file path (with~/+$VARexpansion). - On macOS, add an XDG-style fallback (
$XDG_CONFIG_HOME/~/.config) when the platform-native config path doesn’t exist. - Document the new env var in
config pathoutput and add unit tests for the override/native behavior.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| crates/rustledger/src/config.rs | Implements config-path precedence logic (env override + macOS XDG fallback) and adds unit tests. |
| crates/rustledger/src/cmd/config_cmd.rs | Documents RLEDGER_CONFIG in the config path command output. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Contributor
📊 Benchmark Results
vs main branch (2026-06-30)
What do these numbers mean?
|
Contributor
✅ Compatibility Test Results
What's tested
Full results available in workflow artifacts |
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
10 of 20 tasks
13 of 20 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Addresses discussion #1616 — cross-platform config location for chezmoi/home-manager users.
Problem
rledgerresolves its user config viadirs::config_dir()(platform-native):~/.configon Linux but~/Library/Application Supporton macOS, anddirsignoresXDG_CONFIG_HOMEon macOS. So a single~/.config/rledger/config.tomlcouldn't work on both platforms, and there was no env-var override for the config location.Fix
user_config_path()now resolves in precedence order:$RLEDGER_CONFIG— an explicit config file path (~and$VARexpanded). Highest precedence; the clean answer for chezmoi/home-manager.dirs::config_dir()/rledger/config.toml.$XDG_CONFIG_HOME/~/.config/rledger/config.tomlwhen it exists — so an XDG-style dotfile "just works" on macOS too, with no env var.The override logic is a pure, unit-tested helper (
resolve_user_config_path) so it's testable without env mutation (edition 2024 makesset_varunsafe/flaky).config_cmd's env-var help documentsRLEDGER_CONFIG.Tests / verify
New unit tests cover the
$RLEDGER_CONFIGoverride (absolute +~-expansion) and the no-override native path.cargo build/test/clippy (-D warnings)/fmt clean.🤖 Generated with Claude Code