Skip to content

Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows

docs(config,shell): correct etcetera macOS path docstrings (#2881)

Worktrunk Bot08a8c26ab5d8
diff --git a/src/config/user/path.rs b/src/config/user/path.rs
index 08545dac4..c9bfcf3c7 100644
--- a/src/config/user/path.rs
+++ b/src/config/user/path.rs
@@ -64,10 +64,11 @@ pub fn require_config_path() -> Result<PathBuf, ConfigError> {
/// Returns the etcetera-based platform default. Called by `config_path()`
/// as the final fallback when no CLI or env var override is set.
///
-///
-/// Uses the `etcetera` crate which returns:
-/// - Linux: `$XDG_CONFIG_HOME/worktrunk/config.toml` (default `~/.config/...`)
-/// - macOS: `~/Library/Application Support/worktrunk/config.toml`
+/// `etcetera::choose_base_strategy` follows the CLI convention of using XDG
+/// on every Unix platform (including macOS) and the native APPDATA strategy on
+/// Windows. Concretely:
+/// - Unix (Linux + macOS): `$XDG_CONFIG_HOME/worktrunk/config.toml`
+/// (default `~/.config/worktrunk/config.toml`)
/// - Windows: `%APPDATA%\worktrunk\config.toml`
pub fn default_config_path() -> Option<PathBuf> {
let strategy = choose_base_strategy().ok()?;
diff --git a/src/shell/paths.rs b/src/shell/paths.rs
index f9ca4f583..91877b005 100644
--- a/src/shell/paths.rs
+++ b/src/shell/paths.rs
@@ -66,9 +66,12 @@ fn resolve_nushell_config_dir(home: &std::path::Path, queried: Option<PathBuf>)
/// Get Nushell's default config directory (single best path for writing).
///
/// Used by `completion_path()` to determine where to write completions.
-/// Queries `nu` for `$nu.default-config-dir` to handle platform-specific paths.
-/// On macOS, this is `~/Library/Application Support/nushell` rather than `~/.config/nushell`.
-/// Falls back to etcetera's config_dir if the nu command fails.
+/// Queries `nu` for `$nu.default-config-dir` to handle platform-specific paths
+/// — on macOS without `XDG_CONFIG_HOME` set, Nushell defaults to
+/// `~/Library/Application Support/nushell`, otherwise it follows
+/// `$XDG_CONFIG_HOME/nushell`.
+/// Falls back to etcetera's `config_dir` (which uses XDG on every Unix
+/// platform, so `~/.config/nushell` by default) if the nu command fails.
fn nushell_config_dir(home: &std::path::Path) -> PathBuf {
resolve_nushell_config_dir(home, query_nu_config_dir())
}
@@ -103,8 +106,10 @@ fn nushell_config_candidates(home: &std::path::Path) -> Vec<PathBuf> {
// ~/.config/nushell (XDG default)
candidates.push(home.join(".config").join("nushell"));
- // Platform config dir via etcetera (e.g. ~/Library/Application Support/nushell
- // on macOS, AppData/Roaming/nushell on Windows)
+ // Platform config dir via etcetera. `choose_base_strategy` uses the XDG
+ // strategy on every Unix platform (including macOS), so this resolves to
+ // `$XDG_CONFIG_HOME/nushell` (default `~/.config/nushell`) on Linux and
+ // macOS, and `%APPDATA%\nushell` on Windows.
if let Ok(strategy) = choose_base_strategy() {
candidates.push(strategy.config_dir().join("nushell"));
}
diff --git a/tests/integration_tests/mod.rs b/tests/integration_tests/mod.rs
index 50cfb46f3..99465e22f 100644
--- a/tests/integration_tests/mod.rs
+++ b/tests/integration_tests/mod.rs
@@ -40,6 +40,7 @@ pub mod list_column_alignment;
pub mod list_config;
pub mod list_progressive;
pub mod merge;
+pub mod nushell_default_config_dir;
pub mod output_system_guard;
pub mod post_start_commands;
pub mod push;
diff --git a/tests/integration_tests/nushell_default_config_dir.rs b/tests/integration_tests/nushell_default_config_dir.rs
new file mode 100644
index 000000000..5b89c119a
--- /dev/null
+++ b/tests/integration_tests/nushell_default_config_dir.rs
@@ -0,0 +1,58 @@
+//! Verify Nushell's actual `$nu.default-config-dir` behavior on Unix.
+//!
+//! Backs the docstring claim in `src/shell/paths.rs::nushell_config_dir` (PR
+//! #2881): `$nu.default-config-dir` honors `XDG_CONFIG_HOME` when it is set
+//! (non-empty, absolute), and on macOS falls back to
+//! `~/Library/Application Support/nushell` otherwise. Source of truth:
+//! `nu_path::nu_config_dir` →
+//! <https://github.com/nushell/nushell/blob/0.112.2/crates/nu-path/src/helpers.rs#L22-L44>.
+//!
+//! Gated on `shell-integration-tests` so the test only compiles when the CI
+//! `test-setup` action has installed `nu` (it is installed unconditionally on
+//! non-Windows runners, alongside the other shells these tests need).
+
+#![cfg(all(unix, feature = "shell-integration-tests"))]
+
+use std::process::Command;
+
+fn run_nu_default_config_dir(configure_env: impl FnOnce(&mut Command)) -> String {
+ let mut cmd = Command::new("nu");
+ cmd.args(["-c", "echo $nu.default-config-dir"]);
+ configure_env(&mut cmd);
+ let output = cmd
+ .output()
+ .expect("nu must be on PATH (installed by .github/actions/test-setup)");
+ assert!(
+ output.status.success(),
+ "nu exited non-zero:\nstdout: {}\nstderr: {}",
+ String::from_utf8_lossy(&output.stdout),
+ String::from_utf8_lossy(&output.stderr)
+ );
+ String::from_utf8(output.stdout).unwrap().trim().to_string()
+}
+
+/// `XDG_CONFIG_HOME`, when set to an absolute path, wins on every Unix
+/// (including macOS).
+#[test]
+fn nu_default_config_dir_uses_xdg_when_set() {
+ let temp = tempfile::tempdir().unwrap();
+ let xdg = temp.path().join("custom-xdg");
+ let actual = run_nu_default_config_dir(|cmd| {
+ cmd.env("XDG_CONFIG_HOME", &xdg);
+ });
+ assert_eq!(actual, xdg.join("nushell").to_string_lossy());
+}
+
+/// Without `XDG_CONFIG_HOME`, macOS falls back to
+/// `~/Library/Application Support/nushell` (via `dirs::config_dir()`), not
+/// `~/.config/nushell`.
+#[cfg(target_os = "macos")]
+#[test]
+fn nu_default_config_dir_macos_fallback_is_library_application_support() {
+ let home = std::env::var("HOME").expect("HOME is set on macOS");
+ let actual = run_nu_default_config_dir(|cmd| {
+ cmd.env_remove("XDG_CONFIG_HOME");
+ });
+ let expected = format!("{home}/Library/Application Support/nushell");
+ assert_eq!(actual, expected);
+}