Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
Refactor: Use `etcetera` for config paths for cross-platform consistency
Maximilian Roosd21222319066
diff --git a/CLAUDE.md b/CLAUDE.mdindex 406f16a29..2ddfec404 100644--- a/CLAUDE.md+++ b/CLAUDE.md@@ -2,6 +2,30 @@> **Note**: This CLAUDE.md is just getting started. More guidelines will be added as patterns emerge.+## Project Status++**This project has no users yet and zero backward compatibility concerns.**++We are in **pre-release development** mode:+- Breaking changes are acceptable and expected+- No migration paths needed for config changes, API changes, or behavior changes+- Optimize for the best solution, not compatibility with previous versions+- Move fast and make bold improvements++When making decisions, prioritize:+1. **Best technical solution** over backward compatibility+2. **Clean design** over maintaining old patterns+3. **Modern conventions** over legacy approaches++Examples of acceptable breaking changes:+- Changing config file locations (e.g., moving from `~/Library/Application Support` to `~/.config`)+- Renaming commands or flags for clarity+- Changing output formats+- Replacing dependencies with better alternatives+- Restructuring the codebase++When the project reaches v1.0 or gains users, we'll adopt stability commitments. Until then, we're free to iterate rapidly.+## CLI Output Formatting Standards### The anstyle Ecosystemdiff --git a/Cargo.lock b/Cargo.lockindex 5d2b8e3a5..eed3a9fb8 100644--- a/Cargo.lock+++ b/Cargo.lock@@ -557,27 +557,6 @@ dependencies = ["crypto-common",]-[[package]]-name = "directories"-version = "6.0.0"-source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "16f5094c54661b38d03bd7e50df373292118db60b585c08a411c6d840017fe7d"-dependencies = [- "dirs-sys",-]--[[package]]-name = "dirs-sys"-version = "0.5.0"-source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "e01a3366d27ee9890022452ee61b2b63a67e6f13f58900b651ff5665f0bb1fab"-dependencies = [- "libc",- "option-ext",- "redox_users",- "windows-sys 0.61.2",-]-[[package]]name = "dlv-list"version = "0.5.2"@@ -641,6 +620,17 @@ dependencies = ["windows-sys 0.61.2",]+[[package]]+name = "etcetera"+version = "0.10.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "26c7b13d0780cb82722fd59f6f57f925e143427e4a75313a6c77243bf5326ae6"+dependencies = [+ "cfg-if",+ "home",+ "windows-sys 0.59.0",+]+[[package]]name = "fastrand"version = "2.3.0"@@ -794,6 +784,15 @@ version = "0.5.0"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"+[[package]]+name = "home"+version = "0.5.11"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "589533453244b0995c858700322199b2becb13b627df2851f64a2775d024abcf"+dependencies = [+ "windows-sys 0.59.0",+]+[[package]]name = "iana-time-zone"version = "0.1.64"@@ -908,16 +907,6 @@ version = "0.2.177"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "2874a2af47a2325c2001a6e6fad9b16a53b802102b528163885171cf92b15976"-[[package]]-name = "libredox"-version = "0.1.10"-source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "416f7e718bdb06000964960ffa43b4335ad4012ae8b99060261aa4a8088d5ccb"-dependencies = [- "bitflags",- "libc",-]-[[package]]name = "linux-raw-sys"version = "0.11.0"@@ -978,12 +967,6 @@ version = "11.1.5"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "d6790f58c7ff633d8771f42965289203411a5e5c68388703c06e14f24770b41e"-[[package]]-name = "option-ext"-version = "0.2.0"-source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d"-[[package]]name = "ordered-multimap"version = "0.7.3"@@ -1175,17 +1158,6 @@ dependencies = ["crossbeam-utils",]-[[package]]-name = "redox_users"-version = "0.5.2"-source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "a4e608c6638b9c18977b00b475ac1f28d14e84b27d8d42f70e0bf1e3dec127ac"-dependencies = [- "getrandom 0.2.16",- "libredox",- "thiserror",-]-[[package]]name = "regex"version = "1.12.2"@@ -1472,26 +1444,6 @@ version = "0.5.1"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "8f50febec83f5ee1df3015341d8bd429f2d1cc62bcba7ea2076759d315084683"-[[package]]-name = "thiserror"-version = "2.0.17"-source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "f63587ca0f12b72a0600bcba1d40081f830876000bb46dd2337a3051618f4fc8"-dependencies = [- "thiserror-impl",-]--[[package]]-name = "thiserror-impl"-version = "2.0.17"-source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "3ff15c8ecd7de3849db632e14d18d2571fa09dfc5ed93479bc4485c7a517c913"-dependencies = [- "proc-macro2",- "quote",- "syn",-]-[[package]]name = "time"version = "0.3.44"@@ -2036,7 +1988,7 @@ dependencies = ["clap_complete","config","criterion",- "directories",+ "etcetera","insta","insta-cmd","rayon",diff --git a/Cargo.toml b/Cargo.tomlindex bd6c56212..7dfb03b61 100644--- a/Cargo.toml+++ b/Cargo.toml@@ -24,7 +24,7 @@ chrono = "0.4"clap = { version = "4.5", features = ["derive"] }clap_complete = "4.5"config = "0.15"-directories = "6.0"+etcetera = "0.10"rayon = "1.11"serde = { version = "1.0", features = ["derive"] }serde_json = "1.0"diff --git a/src/commands/config.rs b/src/commands/config.rsindex c004aed5e..d7403caf7 100644--- a/src/commands/config.rs+++ b/src/commands/config.rs@@ -1,4 +1,4 @@-use directories::ProjectDirs;+use etcetera::base_strategy::{BaseStrategy, choose_base_strategy};use std::path::PathBuf;use worktrunk::git::{GitError, Repository};use worktrunk::styling::{AnstyleStyle, HINT, HINT_EMOJI, println};@@ -62,7 +62,7 @@ fn display_project_config() -> Result<(), GitError> {// Try to get current repository rootlet repo = Repository::current();- let repo_root = match repo.main_worktree_root() {+ let repo_root = match repo.worktree_root() {Ok(root) => root,Err(_) => {println!("Project Config: {dim}Not in a git repository{dim:#}");@@ -101,5 +101,6 @@ fn display_project_config() -> Result<(), GitError> {}fn get_global_config_path() -> Option<PathBuf> {- ProjectDirs::from("", "", "worktrunk").map(|dirs| dirs.config_dir().join("config.toml"))+ let strategy = choose_base_strategy().ok()?;+ Some(strategy.config_dir().join("worktrunk").join("config.toml"))}diff --git a/src/config.rs b/src/config.rsindex 7c1a7c01a..2f6a3b6ef 100644--- a/src/config.rs+++ b/src/config.rs@@ -1,5 +1,5 @@use config::{Config, ConfigError, File};-use directories::ProjectDirs;+use etcetera::base_strategy::{BaseStrategy, choose_base_strategy};use serde::{Deserialize, Serialize};use std::path::PathBuf;use toml;@@ -32,8 +32,8 @@ use toml;/// ```////// Config file location:-/// - Linux: `~/.config/worktrunk/config.toml`-/// - macOS: `~/Library/Application Support/worktrunk/config.toml`+/// - Linux: `$XDG_CONFIG_HOME/worktrunk/config.toml` or `~/.config/worktrunk/config.toml`+/// - macOS: `$XDG_CONFIG_HOME/worktrunk/config.toml` or `~/.config/worktrunk/config.toml`/// - Windows: `%APPDATA%\worktrunk\config.toml`////// Environment variable: `WORKTRUNK_WORKTREE_PATH`@@ -112,7 +112,7 @@ impl WorktrunkConfig {////// Configuration is loaded in the following order (later sources override earlier ones):/// 1. Default values- /// 2. Config file (~/.config/worktrunk/config.toml on Linux/macOS)+ /// 2. Config file (see struct documentation for platform-specific paths)/// 3. Environment variables (WORKTRUNK_*)pub fn load() -> Result<Self, ConfigError> {let defaults = Self::default();@@ -162,7 +162,12 @@ impl WorktrunkConfig {}fn get_config_path() -> Option<PathBuf> {- ProjectDirs::from("", "", "worktrunk").map(|dirs| dirs.config_dir().join("config.toml"))+ // choose_base_strategy uses:+ // - XDG on Linux (respects XDG_CONFIG_HOME, falls back to ~/.config)+ // - XDG on macOS (~/.config instead of ~/Library/Application Support)+ // - Windows conventions on Windows (%APPDATA%)+ let strategy = choose_base_strategy().ok()?;+ Some(strategy.config_dir().join("worktrunk").join("config.toml"))}/// Expand template variables in a stringdiff --git a/tests/integration_tests/config_list.rs b/tests/integration_tests/config_list.rsindex 86251e641..14cee863b 100644--- a/tests/integration_tests/config_list.rs+++ b/tests/integration_tests/config_list.rs@@ -11,16 +11,8 @@ fn test_config_list_with_project_config() {let repo = TestRepo::new();let temp_home = TempDir::new().unwrap();- // Create fake global config (platform-specific path)- let global_config_dir = if cfg!(target_os = "macos") {- temp_home- .path()- .join("Library")- .join("Application Support")- .join("worktrunk")- } else {- temp_home.path().join(".config").join("worktrunk")- };+ // Create fake global config at XDG path (used on all platforms with etcetera)+ let global_config_dir = temp_home.path().join(".config").join("worktrunk");fs::create_dir_all(&global_config_dir).unwrap();fs::write(global_config_dir.join("config.toml"),@@ -73,16 +65,8 @@ fn test_config_list_no_project_config() {let repo = TestRepo::new();let temp_home = TempDir::new().unwrap();- // Create fake global config (but no project config) - platform-specific path- let global_config_dir = if cfg!(target_os = "macos") {- temp_home- .path()- .join("Library")- .join("Application Support")- .join("worktrunk")- } else {- temp_home.path().join(".config").join("worktrunk")- };+ // Create fake global config (but no project config) at XDG path+ let global_config_dir = temp_home.path().join(".config").join("worktrunk");fs::create_dir_all(&global_config_dir).unwrap();fs::write(global_config_dir.join("config.toml"),@@ -117,16 +101,8 @@ fn test_config_list_outside_git_repo() {let temp_dir = tempfile::tempdir().unwrap();let temp_home = TempDir::new().unwrap();- // Create fake global config - platform-specific path- let global_config_dir = if cfg!(target_os = "macos") {- temp_home- .path()- .join("Library")- .join("Application Support")- .join("worktrunk")- } else {- temp_home.path().join(".config").join("worktrunk")- };+ // Create fake global config at XDG path+ let global_config_dir = temp_home.path().join(".config").join("worktrunk");fs::create_dir_all(&global_config_dir).unwrap();fs::write(global_config_dir.join("config.toml"),diff --git a/tests/integration_tests/e2e_shell_post_start.rs b/tests/integration_tests/e2e_shell_post_start.rsindex 1ab979f0a..0a5180f7f 100644--- a/tests/integration_tests/e2e_shell_post_start.rs+++ b/tests/integration_tests/e2e_shell_post_start.rs@@ -152,9 +152,7 @@ fn test_e2e_post_start_background_command(#[case] shell: &str) {repo.commit("Add post-start config");// Pre-approve the command- let user_config_dir = temp_home- .path()- .join("Library/Application Support/worktrunk");+ let user_config_dir = temp_home.path().join(".config/worktrunk");fs::create_dir_all(&user_config_dir).expect("Failed to create user config dir");fs::write(user_config_dir.join("config.toml"),@@ -280,9 +278,7 @@ task2 = "sleep 0.5 && echo 'Task 2' > task2.txt"repo.commit("Add multiple post-start commands");// Pre-approve commands- let user_config_dir = temp_home- .path()- .join("Library/Application Support/worktrunk");+ let user_config_dir = temp_home.path().join(".config/worktrunk");fs::create_dir_all(&user_config_dir).expect("Failed to create user config dir");fs::write(user_config_dir.join("config.toml"),@@ -368,9 +364,7 @@ fn test_bash_post_create_blocks() {repo.commit("Add post-create command");// Pre-approve command- let user_config_dir = temp_home- .path()- .join("Library/Application Support/worktrunk");+ let user_config_dir = temp_home.path().join(".config/worktrunk");fs::create_dir_all(&user_config_dir).expect("Failed to create user config dir");fs::write(user_config_dir.join("config.toml"),@@ -456,9 +450,7 @@ fish_bg = "sleep 0.5 && echo 'Fish background done' > fish_bg.txt"repo.commit("Add fish background command");// Pre-approve command- let user_config_dir = temp_home- .path()- .join("Library/Application Support/worktrunk");+ let user_config_dir = temp_home.path().join(".config/worktrunk");fs::create_dir_all(&user_config_dir).expect("Failed to create user config dir");fs::write(user_config_dir.join("config.toml"),diff --git a/tests/integration_tests/post_start_commands.rs b/tests/integration_tests/post_start_commands.rsindex 2996de373..8cce93c2f 100644--- a/tests/integration_tests/post_start_commands.rs+++ b/tests/integration_tests/post_start_commands.rs@@ -67,9 +67,7 @@ fn test_post_create_single_command() {repo.commit("Add config");// Pre-approve the command by setting up the user config in temp HOME- let user_config_dir = temp_home- .path()- .join("Library/Application Support/worktrunk");+ let user_config_dir = temp_home.path().join(".config/worktrunk");fs::create_dir_all(&user_config_dir).expect("Failed to create user config dir");fs::write(user_config_dir.join("config.toml"),@@ -109,9 +107,7 @@ fn test_post_create_multiple_commands_array() {repo.commit("Add config with multiple commands");// Pre-approve both commands in temp HOME- let user_config_dir = temp_home- .path()- .join("Library/Application Support/worktrunk");+ let user_config_dir = temp_home.path().join(".config/worktrunk");fs::create_dir_all(&user_config_dir).expect("Failed to create user config dir");fs::write(user_config_dir.join("config.toml"),@@ -158,9 +154,7 @@ setup = "echo 'Running setup'"repo.commit("Add config with named commands");// Pre-approve both commands in temp HOME- let user_config_dir = temp_home- .path()- .join("Library/Application Support/worktrunk");+ let user_config_dir = temp_home.path().join(".config/worktrunk");fs::create_dir_all(&user_config_dir).expect("Failed to create user config dir");fs::write(user_config_dir.join("config.toml"),@@ -204,9 +198,7 @@ fn test_post_create_failing_command() {repo.commit("Add config with failing command");// Pre-approve the command in temp HOME- let user_config_dir = temp_home- .path()- .join("Library/Application Support/worktrunk");+ let user_config_dir = temp_home.path().join(".config/worktrunk");fs::create_dir_all(&user_config_dir).expect("Failed to create user config dir");fs::write(user_config_dir.join("config.toml"),@@ -251,9 +243,7 @@ fn test_post_create_template_expansion() {repo.commit("Add config with templates");// Pre-approve all commands in temp HOME- let user_config_dir = temp_home- .path()- .join("Library/Application Support/worktrunk");+ let user_config_dir = temp_home.path().join(".config/worktrunk");fs::create_dir_all(&user_config_dir).expect("Failed to create user config dir");let repo_name = "main";fs::write(@@ -337,9 +327,7 @@ fn test_post_start_single_background_command() {repo.commit("Add background command");// Pre-approve the command- let user_config_dir = temp_home- .path()- .join("Library/Application Support/worktrunk");+ let user_config_dir = temp_home.path().join(".config/worktrunk");fs::create_dir_all(&user_config_dir).expect("Failed to create user config dir");fs::write(user_config_dir.join("config.toml"),@@ -398,9 +386,7 @@ task2 = "echo 'Task 2 running' > task2.txt"repo.commit("Add multiple background commands");// Pre-approve both commands- let user_config_dir = temp_home- .path()- .join("Library/Application Support/worktrunk");+ let user_config_dir = temp_home.path().join(".config/worktrunk");fs::create_dir_all(&user_config_dir).expect("Failed to create user config dir");fs::write(user_config_dir.join("config.toml"),@@ -456,9 +442,7 @@ server = "sleep 0.5 && echo 'Server running' > server.txt"repo.commit("Add both command types");// Pre-approve all commands- let user_config_dir = temp_home- .path()- .join("Library/Application Support/worktrunk");+ let user_config_dir = temp_home.path().join(".config/worktrunk");fs::create_dir_all(&user_config_dir).expect("Failed to create user config dir");fs::write(user_config_dir.join("config.toml"),@@ -542,9 +526,7 @@ fn test_post_start_log_file_captures_output() {repo.commit("Add command with stdout/stderr");// Pre-approve the command- let user_config_dir = temp_home- .path()- .join("Library/Application Support/worktrunk");+ let user_config_dir = temp_home.path().join(".config/worktrunk");fs::create_dir_all(&user_config_dir).expect("Failed to create user config dir");fs::write(user_config_dir.join("config.toml"),@@ -621,9 +603,7 @@ fn test_post_start_invalid_command_handling() {repo.commit("Add invalid command");// Pre-approve the command- let user_config_dir = temp_home- .path()- .join("Library/Application Support/worktrunk");+ let user_config_dir = temp_home.path().join(".config/worktrunk");fs::create_dir_all(&user_config_dir).expect("Failed to create user config dir");fs::write(user_config_dir.join("config.toml"),@@ -674,9 +654,7 @@ task3 = "echo 'TASK3_OUTPUT'"repo.commit("Add three background commands");// Pre-approve all commands- let user_config_dir = temp_home- .path()- .join("Library/Application Support/worktrunk");+ let user_config_dir = temp_home.path().join(".config/worktrunk");fs::create_dir_all(&user_config_dir).expect("Failed to create user config dir");fs::write(user_config_dir.join("config.toml"),@@ -778,9 +756,7 @@ fn test_execute_flag_with_post_start_commands() {repo.commit("Add background command");// Pre-approve the command- let user_config_dir = temp_home- .path()- .join("Library/Application Support/worktrunk");+ let user_config_dir = temp_home.path().join(".config/worktrunk");fs::create_dir_all(&user_config_dir).expect("Failed to create user config dir");fs::write(user_config_dir.join("config.toml"),@@ -842,9 +818,7 @@ fn test_post_start_complex_shell_commands() {repo.commit("Add complex shell command");// Pre-approve the command- let user_config_dir = temp_home- .path()- .join("Library/Application Support/worktrunk");+ let user_config_dir = temp_home.path().join(".config/worktrunk");fs::create_dir_all(&user_config_dir).expect("Failed to create user config dir");fs::write(user_config_dir.join("config.toml"),diff --git a/tests/integration_tests/switch.rs b/tests/integration_tests/switch.rsindex f9e76eab9..ba963a238 100644--- a/tests/integration_tests/switch.rs+++ b/tests/integration_tests/switch.rs@@ -274,9 +274,7 @@ fn test_switch_no_config_commands_skips_post_start_commands() {repo.commit("Add config");// Pre-approve the command- let user_config_dir = temp_home- .path()- .join("Library/Application Support/worktrunk");+ let user_config_dir = temp_home.path().join(".config/worktrunk");fs::create_dir_all(&user_config_dir).expect("Failed to create user config dir");fs::write(user_config_dir.join("config.toml"),diff --git a/tests/snapshots/integration__integration_tests__config_list__config_list_no_project.snap b/tests/snapshots/integration__integration_tests__config_list__config_list_no_project.snapindex b5d9e7276..426c68636 100644--- a/tests/snapshots/integration__integration_tests__config_list__config_list_no_project.snap+++ b/tests/snapshots/integration__integration_tests__config_list__config_list_no_project.snap@@ -12,7 +12,7 @@ info:GIT_CONFIG_GLOBAL: /dev/nullGIT_CONFIG_SYSTEM: /dev/nullGIT_EDITOR: ""- HOME: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpgLlPGc+ HOME: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpRuEH5NLANG: CLC_ALL: CSOURCE_DATE_EPOCH: "1704067200"@@ -20,7 +20,7 @@ info:success: trueexit_code: 0----- stdout ------Global Config: [1m[TEMP_HOME]/Library/Application Support/worktrunk/config.toml[0m+Global Config: [1m[TEMP_HOME]/.config/worktrunk/config.toml[0m[2mworktree-path = "../{repo}.{branch}"[0mProject Config: [1m[REPO]/.config/wt.toml[0mdiff --git a/tests/snapshots/integration__integration_tests__config_list__config_list_outside_repo.snap b/tests/snapshots/integration__integration_tests__config_list__config_list_outside_repo.snapindex c153a78b0..24259ca26 100644--- a/tests/snapshots/integration__integration_tests__config_list__config_list_outside_repo.snap+++ b/tests/snapshots/integration__integration_tests__config_list__config_list_outside_repo.snap@@ -6,12 +6,12 @@ info:- config- listenv:- HOME: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmppt3s1F+ HOME: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpqVUgYd---success: trueexit_code: 0----- stdout ------Global Config: [TEMP_HOME]/Library/Application Support/worktrunk/config.toml+Global Config: [TEMP_HOME]/.config/worktrunk/config.tomlworktree-path = "../{repo}.{branch}"Project Config: Not in a git repositorydiff --git a/tests/snapshots/integration__integration_tests__config_list__config_list_with_project.snap b/tests/snapshots/integration__integration_tests__config_list__config_list_with_project.snapindex 4ee6e47af..6b9c28621 100644--- a/tests/snapshots/integration__integration_tests__config_list__config_list_with_project.snap+++ b/tests/snapshots/integration__integration_tests__config_list__config_list_with_project.snap@@ -12,7 +12,7 @@ info:GIT_CONFIG_GLOBAL: /dev/nullGIT_CONFIG_SYSTEM: /dev/nullGIT_EDITOR: ""- HOME: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpS3zikH+ HOME: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpfh2xeSLANG: CLC_ALL: CSOURCE_DATE_EPOCH: "1704067200"@@ -20,7 +20,7 @@ info:success: trueexit_code: 0----- stdout ------Global Config: [1m[TEMP_HOME]/Library/Application Support/worktrunk/config.toml[0m+Global Config: [1m[TEMP_HOME]/.config/worktrunk/config.toml[0m[2mworktree-path = "../{repo}.{branch}"[0m[2m[[approved-commands]][0m