Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
feat: Add config list command and update CLAUDE.md
Maximilian Roos09026cde6a42
diff --git a/CLAUDE.md b/CLAUDE.mdindex d9e5a8f0a..406f16a29 100644--- a/CLAUDE.md+++ b/CLAUDE.md@@ -104,6 +104,41 @@ println!("Switched to worktree: {bold}{branch}{bold:#}");println!("Switched to worktree: {branch}")```+### Information Hierarchy & Path Styling++**Principle: Bold what answers the user's question, dim what provides context.**++Style elements based on **user intent**, not data type. The same information (like a file path) can be primary in one context and secondary in another.++**File paths:**++- **Primary information** (answering the user's main question): **Bold**+ - Example: `wt config list` - paths are the answer to "where is my config?"++- **Secondary information** (contextual metadata): **Dim**+ - Example: `wt switch` output - path provides context, branch name is the answer++```rust+use worktrunk::styling::AnstyleStyle;++// Path as primary answer (config list)+let bold = AnstyleStyle::new().bold();+println!("Global Config: {bold}{}{bold:#}", path.display());++// Path as secondary context (switch output)+let dim = AnstyleStyle::new().dimmed();+println!("β Created {bold}{branch}{bold:#}\n {dim}Path: {}{dim:#}", path.display());+```++**Visual hierarchy patterns:**++| Element | Primary (answers question) | Secondary (provides context) |+|---------|---------------------------|------------------------------|+| Branch names | **Bold** (always) | **Bold** (always) |+| File paths | **Bold** (`config list`) | **Dim** (`switch` output) |+| Config values | Normal | **Dim** |+| Metadata | Dim | **Dim** |+### Color DetectionColors automatically adjust based on environment:diff --git a/src/commands/config.rs b/src/commands/config.rsnew file mode 100644index 000000000..f8bfb5a88--- /dev/null+++ b/src/commands/config.rs@@ -0,0 +1,105 @@+use directories::ProjectDirs;+use std::path::PathBuf;+use worktrunk::git::{GitError, Repository};+use worktrunk::styling::{AnstyleStyle, HINT, HINT_EMOJI, println};++/// Handle the config list command+pub fn handle_config_list() -> Result<(), GitError> {+ // Display global config+ display_global_config()?;+ println!();++ // Display project config if in a git repository+ display_project_config()?;++ Ok(())+}++fn display_global_config() -> Result<(), GitError> {+ let bold = AnstyleStyle::new().bold();+ let dim = AnstyleStyle::new().dimmed();++ // Get config path+ let config_path = get_global_config_path().ok_or_else(|| {+ GitError::CommandFailed("Could not determine global config path".to_string())+ })?;++ println!("Global Config: {bold}{}{bold:#}", config_path.display());++ // Check if file exists+ if !config_path.exists() {+ println!(" {HINT_EMOJI} {HINT}Not found (using defaults){HINT:#}");+ println!();+ println!(" {dim}# Default configuration:{dim:#}");+ println!(" {dim}worktree-path = \"../{{repo}}.{{branch}}\"{dim:#}");+ return Ok(());+ }++ // Read and display the file contents+ let contents = std::fs::read_to_string(&config_path)+ .map_err(|e| GitError::CommandFailed(format!("Failed to read config file: {}", e)))?;++ if contents.trim().is_empty() {+ println!(" {HINT_EMOJI} {HINT}Empty file (using defaults){HINT:#}");+ return Ok(());+ }++ // Display each line with indentation+ for line in contents.lines() {+ if !line.trim().is_empty() {+ println!(" {dim}{line}{dim:#}");+ } else {+ println!();+ }+ }++ Ok(())+}++fn display_project_config() -> Result<(), GitError> {+ let bold = AnstyleStyle::new().bold();+ let dim = AnstyleStyle::new().dimmed();++ // Try to get current repository root+ let repo = Repository::current();+ let repo_root = match repo.repo_root() {+ Ok(root) => root,+ Err(_) => {+ println!("Project Config: {dim}Not in a git repository{dim:#}");+ return Ok(());+ }+ };+ let config_path = repo_root.join(".config").join("wt.toml");++ println!("Project Config: {bold}{}{bold:#}", config_path.display());++ // Check if file exists+ if !config_path.exists() {+ println!(" {HINT_EMOJI} {HINT}Not found{HINT:#}");+ return Ok(());+ }++ // Read and display the file contents+ let contents = std::fs::read_to_string(&config_path)+ .map_err(|e| GitError::CommandFailed(format!("Failed to read config file: {}", e)))?;++ if contents.trim().is_empty() {+ println!(" {HINT_EMOJI} {HINT}Empty file{HINT:#}");+ return Ok(());+ }++ // Display each line with indentation+ for line in contents.lines() {+ if !line.trim().is_empty() {+ println!(" {dim}{line}{dim:#}");+ } else {+ println!();+ }+ }++ Ok(())+}++fn get_global_config_path() -> Option<PathBuf> {+ ProjectDirs::from("", "", "worktrunk").map(|dirs| dirs.config_dir().join("config.toml"))+}diff --git a/src/commands/mod.rs b/src/commands/mod.rsindex eb1a6c146..e5a6d118a 100644--- a/src/commands/mod.rs+++ b/src/commands/mod.rs@@ -1,4 +1,5 @@pub mod completion;+pub mod config;pub mod configure_shell;pub mod init;pub mod list;@@ -7,6 +8,7 @@ pub mod process;pub mod worktree;pub use completion::{handle_complete, handle_completion};+pub use config::handle_config_list;pub use configure_shell::{ConfigAction, handle_configure_shell};pub use init::handle_init;pub use list::handle_list;diff --git a/src/main.rs b/src/main.rsindex dd2885dda..74509e67d 100644--- a/src/main.rs+++ b/src/main.rs@@ -11,8 +11,9 @@ mod llm;mod output;use commands::{- ConfigAction, Shell, handle_complete, handle_completion, handle_configure_shell, handle_init,- handle_list, handle_merge, handle_push, handle_remove, handle_switch,+ ConfigAction, Shell, handle_complete, handle_completion, handle_config_list,+ handle_configure_shell, handle_init, handle_list, handle_merge, handle_push, handle_remove,+ handle_switch,};use output::{handle_remove_output, handle_switch_output};@@ -34,6 +35,12 @@ struct Cli {command: Commands,}+#[derive(Subcommand)]+enum ConfigCommand {+ /// List all configuration files and their locations+ List,+}+#[derive(Subcommand)]enum Commands {/// Generate shell integration code@@ -61,6 +68,12 @@ enum Commands {yes: bool,},+ /// Manage configuration+ Config {+ #[command(subcommand)]+ action: ConfigCommand,+ },+/// List all worktreesList {/// Output format@@ -211,6 +224,9 @@ fn main() {}).map_err(GitError::CommandFailed)}+ Commands::Config { action } => match action {+ ConfigCommand::List => handle_config_list(),+ },Commands::List { format, branches } => handle_list(format, branches),Commands::Switch {branch,diff --git a/tests/integration_tests/config_list.rs b/tests/integration_tests/config_list.rsnew file mode 100644index 000000000..86251e641--- /dev/null+++ b/tests/integration_tests/config_list.rs@@ -0,0 +1,154 @@+use crate::common::TestRepo;+use insta::Settings;+use insta_cmd::{assert_cmd_snapshot, get_cargo_bin};+use std::fs;+use std::process::Command;+use tempfile::TempDir;++/// Test `wt config list` with both global and project configs present+#[test]+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")+ };+ fs::create_dir_all(&global_config_dir).unwrap();+ fs::write(+ global_config_dir.join("config.toml"),+ r#"worktree-path = "../{repo}.{branch}"++[[approved-commands]]+project = "test-project"+command = "npm install"+"#,+ )+ .unwrap();++ // Create project config+ let config_dir = repo.root_path().join(".config");+ fs::create_dir_all(&config_dir).unwrap();+ fs::write(+ config_dir.join("wt.toml"),+ r#"post-create-command = "npm install"++[post-start-command]+server = "npm run dev"+"#,+ )+ .unwrap();++ let mut settings = Settings::clone_current();+ settings.set_snapshot_path("../snapshots");++ // Filter out the actual config paths to use placeholders+ settings.add_filter(repo.root_path().to_str().unwrap(), "[REPO]");+ settings.add_filter(&temp_home.path().to_string_lossy(), "[TEMP_HOME]");+ // Normalize Windows paths to Unix style+ settings.add_filter(r"\\", "/");++ settings.bind(|| {+ let mut cmd = Command::new(get_cargo_bin("wt"));+ repo.clean_cli_env(&mut cmd);+ cmd.arg("config")+ .arg("list")+ .env("HOME", temp_home.path())+ .current_dir(repo.root_path());++ assert_cmd_snapshot!("config_list_with_project", cmd);+ });+}++/// Test `wt config list` when there is no project config+#[test]+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")+ };+ fs::create_dir_all(&global_config_dir).unwrap();+ fs::write(+ global_config_dir.join("config.toml"),+ r#"worktree-path = "../{repo}.{branch}"+"#,+ )+ .unwrap();++ let mut settings = Settings::clone_current();+ settings.set_snapshot_path("../snapshots");++ // Filter out the actual config paths to use placeholders+ settings.add_filter(repo.root_path().to_str().unwrap(), "[REPO]");+ settings.add_filter(&temp_home.path().to_string_lossy(), "[TEMP_HOME]");+ settings.add_filter(r"\\", "/");++ settings.bind(|| {+ let mut cmd = Command::new(get_cargo_bin("wt"));+ repo.clean_cli_env(&mut cmd);+ cmd.arg("config")+ .arg("list")+ .env("HOME", temp_home.path())+ .current_dir(repo.root_path());++ assert_cmd_snapshot!("config_list_no_project", cmd);+ });+}++/// Test `wt config list` outside a git repository+#[test]+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")+ };+ fs::create_dir_all(&global_config_dir).unwrap();+ fs::write(+ global_config_dir.join("config.toml"),+ r#"worktree-path = "../{repo}.{branch}"+"#,+ )+ .unwrap();++ let mut settings = Settings::clone_current();+ settings.set_snapshot_path("../snapshots");++ // Filter out the actual config paths+ settings.add_filter(&temp_home.path().to_string_lossy(), "[TEMP_HOME]");+ settings.add_filter(r"\\", "/");++ settings.bind(|| {+ let mut cmd = Command::new(get_cargo_bin("wt"));+ cmd.arg("config")+ .arg("list")+ .env("HOME", temp_home.path())+ .current_dir(temp_dir.path());++ assert_cmd_snapshot!("config_list_outside_repo", cmd);+ });+}diff --git a/tests/integration_tests/mod.rs b/tests/integration_tests/mod.rsindex 80319e448..0180663b9 100644--- a/tests/integration_tests/mod.rs+++ b/tests/integration_tests/mod.rs@@ -2,6 +2,7 @@pub mod column_alignment_verification;pub mod completion;pub mod completion_validation;+pub mod config_list;pub mod configure_shell;pub mod default_branch;pub mod directives;diff --git a/tests/snapshots/integration__integration_tests__configure_shell__configure_shell_dry_run.snap b/tests/snapshots/integration__integration_tests__config_list__config_list_no_project.snapsimilarity index 51%rename from tests/snapshots/integration__integration_tests__configure_shell__configure_shell_dry_run.snaprename to tests/snapshots/integration__integration_tests__config_list__config_list_no_project.snapindex a52224bc5..b5d9e7276 100644--- a/tests/snapshots/integration__integration_tests__configure_shell__configure_shell_dry_run.snap+++ b/tests/snapshots/integration__integration_tests__config_list__config_list_no_project.snap@@ -1,10 +1,10 @@----source: tests/integration_tests/configure_shell.rs+source: tests/integration_tests/config_list.rsinfo:program: wtargs:- - configure-shell- - "--dry-run"+ - config+ - listenv:CLICOLOR_FORCE: "1"GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"@@ -12,7 +12,7 @@ info:GIT_CONFIG_GLOBAL: /dev/nullGIT_CONFIG_SYSTEM: /dev/nullGIT_EDITOR: ""- HOME: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpsT0i6B+ HOME: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpgLlPGcLANG: CLC_ALL: CSOURCE_DATE_EPOCH: "1704067200"@@ -20,7 +20,10 @@ info:success: trueexit_code: 0----- stdout ------Would add to zsh [TEMP_HOME]/.zshrc- [2meval "$(wt init zsh)"[0m+Global Config: [1m[TEMP_HOME]/Library/Application Support/worktrunk/config.toml[0m+ [2mworktree-path = "../{repo}.{branch}"[0m++Project Config: [1m[REPO]/.config/wt.toml[0m+ π‘ [2mNot found[0m----- stderr -----diff --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.snapnew file mode 100644index 000000000..c153a78b0--- /dev/null+++ b/tests/snapshots/integration__integration_tests__config_list__config_list_outside_repo.snap@@ -0,0 +1,19 @@+---+source: tests/integration_tests/config_list.rs+info:+ program: wt+ args:+ - config+ - list+ env:+ HOME: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmppt3s1F+---+success: true+exit_code: 0+----- stdout -----+Global Config: [TEMP_HOME]/Library/Application Support/worktrunk/config.toml+ worktree-path = "../{repo}.{branch}"++Project Config: Not in a git repository++----- stderr -----diff --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.snapnew file mode 100644index 000000000..4ee6e47af--- /dev/null+++ b/tests/snapshots/integration__integration_tests__config_list__config_list_with_project.snap@@ -0,0 +1,36 @@+---+source: tests/integration_tests/config_list.rs+info:+ program: wt+ args:+ - config+ - list+ env:+ CLICOLOR_FORCE: "1"+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"+ GIT_CONFIG_GLOBAL: /dev/null+ GIT_CONFIG_SYSTEM: /dev/null+ GIT_EDITOR: ""+ HOME: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpS3zikH+ LANG: C+ LC_ALL: C+ SOURCE_DATE_EPOCH: "1704067200"+---+success: true+exit_code: 0+----- stdout -----+Global Config: [1m[TEMP_HOME]/Library/Application Support/worktrunk/config.toml[0m+ [2mworktree-path = "../{repo}.{branch}"[0m++ [2m[[approved-commands]][0m+ [2mproject = "test-project"[0m+ [2mcommand = "npm install"[0m++Project Config: [1m[REPO]/.config/wt.toml[0m+ [2mpost-create-command = "npm install"[0m++ [2m[post-start-command][0m+ [2mserver = "npm run dev"[0m++----- stderr -----diff --git a/tests/snapshots/integration__integration_tests__configure_shell__configure_shell_fish_conf_d_exists.snap b/tests/snapshots/integration__integration_tests__configure_shell__configure_shell_fish_conf_d_exists.snapdeleted file mode 100644index 5ff019549..000000000--- a/tests/snapshots/integration__integration_tests__configure_shell__configure_shell_fish_conf_d_exists.snap+++ /dev/null@@ -1,26 +0,0 @@-----source: tests/integration_tests/configure_shell.rs-info:- program: wt- args:- - configure-shell- - "--dry-run"- env:- CLICOLOR_FORCE: "1"- GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"- GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"- GIT_CONFIG_GLOBAL: /dev/null- GIT_CONFIG_SYSTEM: /dev/null- GIT_EDITOR: ""- HOME: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpFrHXtL- LANG: C- LC_ALL: C- SOURCE_DATE_EPOCH: "1704067200"-----success: true-exit_code: 0------ stdout ------Would create fish [TEMP_HOME]/.config/fish/conf.d/wt.fish- [2mwt init fish | source[0m------- stderr -----diff --git a/tests/snapshots/integration__integration_tests__configure_shell__configure_shell_mixed_states_dry_run.snap b/tests/snapshots/integration__integration_tests__configure_shell__configure_shell_mixed_states_dry_run.snapdeleted file mode 100644index dae43f462..000000000--- a/tests/snapshots/integration__integration_tests__configure_shell__configure_shell_mixed_states_dry_run.snap+++ /dev/null@@ -1,28 +0,0 @@-----source: tests/integration_tests/configure_shell.rs-info:- program: wt- args:- - configure-shell- - "--dry-run"- env:- CLICOLOR_FORCE: "1"- GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"- GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"- GIT_CONFIG_GLOBAL: /dev/null- GIT_CONFIG_SYSTEM: /dev/null- GIT_EDITOR: ""- HOME: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmprQhDXj- LANG: C- LC_ALL: C- SOURCE_DATE_EPOCH: "1704067200"-----success: true-exit_code: 0------ stdout ------Already configured bash [TEMP_HOME]/.bash_profile- [2meval "$(wt init bash)"[0m-Would add to zsh [TEMP_HOME]/.zshrc- [2meval "$(wt init zsh)"[0m------- stderr -----diff --git a/tests/snapshots/integration__integration_tests__init__init_bash.snap b/tests/snapshots/integration__integration_tests__init__init_bash.snapindex 9fd260576..afabe5170 100644--- a/tests/snapshots/integration__integration_tests__init__init_bash.snap+++ b/tests/snapshots/integration__integration_tests__init__init_bash.snap@@ -128,6 +128,9 @@ _wt() {wt,completion)cmd="wt__completion";;+ wt,config)+ cmd="wt__config"+ ;;wt,configure-shell)cmd="wt__configure__shell";;@@ -149,6 +152,9 @@ _wt() {wt,switch)cmd="wt__switch";;+ wt__config,list)+ cmd="wt__config__list"+ ;;*);;esac@@ -156,7 +162,7 @@ _wt() {case "${cmd}" inwt)- opts="-h -V --help --version init configure-shell list switch remove push merge completion complete"+ opts="-h -V --help --version init configure-shell config list switch remove push merge completion complete"if [[ ${cur} == -* || ${COMP_CWORD} -eq 1 ]] ; thenCOMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )return 0@@ -197,6 +203,34 @@ _wt() {COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )return 0;;+ wt__config)+ opts="-h --help list"+ if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then+ COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )+ return 0+ fi+ case "${prev}" in+ *)+ COMPREPLY=()+ ;;+ esac+ COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )+ return 0+ ;;+ wt__config__list)+ opts="-h --help"+ if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then+ COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )+ return 0+ fi+ case "${prev}" in+ *)+ COMPREPLY=()+ ;;+ esac+ COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )+ return 0+ ;;wt__configure__shell)opts="-y -h --shell --cmd --yes --help"if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; thendiff --git a/tests/snapshots/integration__integration_tests__init__init_bash_custom_prefix.snap b/tests/snapshots/integration__integration_tests__init__init_bash_custom_prefix.snapindex 977110e65..cf08a97bd 100644--- a/tests/snapshots/integration__integration_tests__init__init_bash_custom_prefix.snap+++ b/tests/snapshots/integration__integration_tests__init__init_bash_custom_prefix.snap@@ -130,6 +130,9 @@ _wt() {wt,completion)cmd="wt__completion";;+ wt,config)+ cmd="wt__config"+ ;;wt,configure-shell)cmd="wt__configure__shell";;@@ -151,6 +154,9 @@ _wt() {wt,switch)cmd="wt__switch";;+ wt__config,list)+ cmd="wt__config__list"+ ;;*);;esac@@ -158,7 +164,7 @@ _wt() {case "${cmd}" inwt)- opts="-h -V --help --version init configure-shell list switch remove push merge completion complete"+ opts="-h -V --help --version init configure-shell config list switch remove push merge completion complete"if [[ ${cur} == -* || ${COMP_CWORD} -eq 1 ]] ; thenCOMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )return 0@@ -199,6 +205,34 @@ _wt() {COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )return 0;;+ wt__config)+ opts="-h --help list"+ if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then+ COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )+ return 0+ fi+ case "${prev}" in+ *)+ COMPREPLY=()+ ;;+ esac+ COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )+ return 0+ ;;+ wt__config__list)+ opts="-h --help"+ if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then+ COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )+ return 0+ fi+ case "${prev}" in+ *)+ COMPREPLY=()+ ;;+ esac+ COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )+ return 0+ ;;wt__configure__shell)opts="-y -h --shell --cmd --yes --help"if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; thendiff --git a/tests/snapshots/integration__integration_tests__init__init_elvish.snap b/tests/snapshots/integration__integration_tests__init__init_elvish.snapdeleted file mode 100644index d94ce3bd1..000000000--- a/tests/snapshots/integration__integration_tests__init__init_elvish.snap+++ /dev/null@@ -1,81 +0,0 @@-----source: tests/integration_tests/init.rs-info:- program: wt- args:- - init- - elvish- env:- CLICOLOR_FORCE: "1"- GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"- GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"- GIT_CONFIG_GLOBAL: /dev/null- GIT_CONFIG_SYSTEM: /dev/null- GIT_EDITOR: ""- LANG: C- LC_ALL: C- SOURCE_DATE_EPOCH: "1704067200"-----success: false-exit_code: 1------ stdout ------# worktrunk shell integration for elvish--# Only initialize if wt is available-if (has-external wt) {- # Helper function to parse wt output and handle directives- fn _wt_exec {|@args|- var exit-code = 0- var output = ""-- # Capture output and handle potential non-zero exit- try {- set output = (e:wt $@args 2>&1 | slurp)- } catch e {- set exit-code = 1- set output = $e[reason][content]- }-- # Parse output line by line- var lines = [(str:split "\n" $output)]- for line $lines {- if (str:has-prefix $line "__WORKTRUNK_CD__") {- # Extract path and change directory- var path = (str:trim-prefix $line "__WORKTRUNK_CD__")- cd $path- } else {- # Regular output - print it- echo $line- }- }-- # Return exit code (will throw exception if non-zero)- if (!=s $exit-code 0) {- fail "command failed with exit code "$exit-code- }- }-- # Override wt command to add --internal flag for switch, remove, and merge- fn wt {|@args|- if (== (count $args) 0) {- e:wt- return- }-- var subcommand = $args[0]-- if (or (eq $subcommand "switch") (eq $subcommand "remove") (eq $subcommand "merge")) {- # Commands that need --internal for directory change support- var rest-args = $args[1..]- _wt_exec $subcommand --internal $@rest-args- } else {- # All other commands pass through directly- e:wt $@args- }- }-}--# Static completions (commands and flags)------- stderr ------β [31mCompletion not yet supported for elvish[0mdiff --git a/tests/snapshots/integration__integration_tests__init__init_fish.snap b/tests/snapshots/integration__integration_tests__init__init_fish.snapindex 63cabc1ae..562c66b23 100644--- a/tests/snapshots/integration__integration_tests__init__init_fish.snap+++ b/tests/snapshots/integration__integration_tests__init__init_fish.snap@@ -140,6 +140,7 @@ complete -c wt -n "__fish_wt_needs_command" -s h -l help -d 'Print help'complete -c wt -n "__fish_wt_needs_command" -s V -l version -d 'Print version'complete -c wt -n "__fish_wt_needs_command" -f -a "init" -d 'Generate shell integration code'complete -c wt -n "__fish_wt_needs_command" -f -a "configure-shell" -d 'Configure shell by writing to config files'+complete -c wt -n "__fish_wt_needs_command" -f -a "config" -d 'Manage configuration'complete -c wt -n "__fish_wt_needs_command" -f -a "list" -d 'List all worktrees'complete -c wt -n "__fish_wt_needs_command" -f -a "switch" -d 'Switch to a worktree'complete -c wt -n "__fish_wt_needs_command" -f -a "remove" -d 'Finish current worktree, returning to primary if current'@@ -158,6 +159,9 @@ zsh\t''"complete -c wt -n "__fish_wt_using_subcommand configure-shell" -l cmd -d 'Command prefix (default: wt)' -rcomplete -c wt -n "__fish_wt_using_subcommand configure-shell" -s y -l yes -d 'Skip confirmation prompt'complete -c wt -n "__fish_wt_using_subcommand configure-shell" -s h -l help -d 'Print help'+complete -c wt -n "__fish_wt_using_subcommand config; and not __fish_seen_subcommand_from list" -s h -l help -d 'Print help'+complete -c wt -n "__fish_wt_using_subcommand config; and not __fish_seen_subcommand_from list" -f -a "list" -d 'List all configuration files and their locations'+complete -c wt -n "__fish_wt_using_subcommand config; and __fish_seen_subcommand_from list" -s h -l help -d 'Print help'complete -c wt -n "__fish_wt_using_subcommand list" -l format -d 'Output format' -r -f -a "table\t'Human-readable table format'json\t'JSON format'"complete -c wt -n "__fish_wt_using_subcommand list" -l branches -d 'Also display branches that don\'t have worktrees'diff --git a/tests/snapshots/integration__integration_tests__init__init_nushell.snap b/tests/snapshots/integration__integration_tests__init__init_nushell.snapdeleted file mode 100644index 53579ed42..000000000--- a/tests/snapshots/integration__integration_tests__init__init_nushell.snap+++ /dev/null@@ -1,71 +0,0 @@-----source: tests/integration_tests/init.rs-info:- program: wt- args:- - init- - nushell- env:- CLICOLOR_FORCE: "1"- GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"- GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"- GIT_CONFIG_GLOBAL: /dev/null- GIT_CONFIG_SYSTEM: /dev/null- GIT_EDITOR: ""- LANG: C- LC_ALL: C- SOURCE_DATE_EPOCH: "1704067200"-----success: false-exit_code: 1------ stdout ------# worktrunk shell integration for nushell--# Only initialize if wt is available-if (which wt | is-not-empty) {- # Helper function to parse wt output and handle directives- export def --env _wt_exec [...args] {- let result = (do { ^wt ...$args } | complete)-- # Parse output line by line- let lines = ($result.stdout | lines)- for line in $lines {- if ($line | str starts-with "__WORKTRUNK_CD__") {- # Extract path and change directory- let path = ($line | str substring 16..)- cd $path- } else {- # Regular output - print it- print $line- }- }-- # Return the exit code- return $result.exit_code- }-- # Override wt command to add --internal flag for switch, remove, and merge- # Use --wrapped to pass through all flags without parsing them- export def --env --wrapped wt [...rest] {- let subcommand = ($rest | get 0? | default "")-- match $subcommand {- "switch" | "remove" | "merge" => {- # Commands that need --internal for directory change support- let rest_args = ($rest | skip 1)- let internal_args = ([$subcommand, "--internal"] | append $rest_args)- let exit_code = (_wt_exec ...$internal_args)- return $exit_code- }- _ => {- # All other commands pass through directly- ^wt ...$rest- }- }- }-}--# Static completions (commands and flags)------- stderr ------β [31mCompletion not yet supported for nushell[0mdiff --git a/tests/snapshots/integration__integration_tests__init__init_oil.snap b/tests/snapshots/integration__integration_tests__init__init_oil.snapdeleted file mode 100644index b8ecb6dfe..000000000--- a/tests/snapshots/integration__integration_tests__init__init_oil.snap+++ /dev/null@@ -1,309 +0,0 @@-----source: tests/integration_tests/init.rs-info:- program: wt- args:- - init- - oil- env:- CLICOLOR_FORCE: "1"- GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"- GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"- GIT_CONFIG_GLOBAL: /dev/null- GIT_CONFIG_SYSTEM: /dev/null- GIT_EDITOR: ""- LANG: C- LC_ALL: C- SOURCE_DATE_EPOCH: "1704067200"-----success: true-exit_code: 0------ stdout ------# worktrunk shell integration for oil--# Only initialize if wt is available-if command -v wt >/dev/null 2>&1; then- # Helper function to parse wt output and handle directives- _wt_exec() {- local output line exit_code- output="$(command wt "$@" 2>&1)"- exit_code=$?-- # Parse output line by line- while IFS= read -r line; do- if [[ "$line" == __WORKTRUNK_CD__* ]]; then- # Extract path and change directory- \cd "${line#__WORKTRUNK_CD__}"- else- # Regular output - print it- echo "$line"- fi- done <<< "$output"-- return $exit_code- }-- # Override wt command to add --internal flag for switch, remove, and merge- wt() {- local subcommand="$1"-- case "$subcommand" in- switch|remove|merge)- # Commands that need --internal for directory change support- shift- _wt_exec "$subcommand" --internal "$@"- ;;- *)- # All other commands pass through directly- command wt "$@"- ;;- esac- }-- # Dynamic completion function- _wt_complete() {- local cur="${COMP_WORDS[COMP_CWORD]}"-- # Call wt complete with current command line- local completions=$(command wt complete "${COMP_WORDS[@]}" 2>/dev/null)- COMPREPLY=($(compgen -W "$completions" -- "$cur"))- }-- # Register dynamic completion- complete -F _wt_complete wt-fi--# Static completions (commands and flags)-_wt() {- local i cur prev opts cmd- COMPREPLY=()- if [[ "${BASH_VERSINFO[0]}" -ge 4 ]]; then- cur="$2"- else- cur="${COMP_WORDS[COMP_CWORD]}"- fi- prev="$3"- cmd=""- opts=""-- for i in "${COMP_WORDS[@]:0:COMP_CWORD}"- do- case "${cmd},${i}" in- ",$1")- cmd="wt"- ;;- wt,complete)- cmd="wt__complete"- ;;- wt,completion)- cmd="wt__completion"- ;;- wt,configure-shell)- cmd="wt__configure__shell"- ;;- wt,init)- cmd="wt__init"- ;;- wt,list)- cmd="wt__list"- ;;- wt,merge)- cmd="wt__merge"- ;;- wt,push)- cmd="wt__push"- ;;- wt,remove)- cmd="wt__remove"- ;;- wt,switch)- cmd="wt__switch"- ;;- *)- ;;- esac- done-- case "${cmd}" in- wt)- opts="-h -V --help --version init configure-shell list switch remove push merge completion complete"- if [[ ${cur} == -* || ${COMP_CWORD} -eq 1 ]] ; then- COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )- return 0- fi- case "${prev}" in- *)- COMPREPLY=()- ;;- esac- COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )- return 0- ;;- wt__complete)- opts="-h --help [ARGS]..."- if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then- COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )- return 0- fi- case "${prev}" in- *)- COMPREPLY=()- ;;- esac- COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )- return 0- ;;- wt__completion)- opts="-h --help bash elvish fish nushell oil powershell xonsh zsh"- if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then- COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )- return 0- fi- case "${prev}" in- *)- COMPREPLY=()- ;;- esac- COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )- return 0- ;;- wt__configure__shell)- opts="-y -h --shell --cmd --yes --help"- if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then- COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )- return 0- fi- case "${prev}" in- --shell)- COMPREPLY=($(compgen -W "bash elvish fish nushell oil powershell xonsh zsh" -- "${cur}"))- return 0- ;;- --cmd)- COMPREPLY=($(compgen -f "${cur}"))- return 0- ;;- *)- COMPREPLY=()- ;;- esac- COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )- return 0- ;;- wt__init)- opts="-h --cmd --help <SHELL>"- if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then- COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )- return 0- fi- case "${prev}" in- --cmd)- COMPREPLY=($(compgen -f "${cur}"))- return 0- ;;- *)- COMPREPLY=()- ;;- esac- COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )- return 0- ;;- wt__list)- opts="-h --format --branches --help"- if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then- COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )- return 0- fi- case "${prev}" in- --format)- COMPREPLY=($(compgen -W "table json" -- "${cur}"))- return 0- ;;- *)- COMPREPLY=()- ;;- esac- COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )- return 0- ;;- wt__merge)- opts="-s -k -h --squash --keep --help [TARGET]"- if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then- COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )- return 0- fi- case "${prev}" in- *)- COMPREPLY=()- ;;- esac- COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )- return 0- ;;- wt__push)- opts="-h --allow-merge-commits --help [TARGET]"- if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then- COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )- return 0- fi- case "${prev}" in- *)- COMPREPLY=()- ;;- esac- COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )- return 0- ;;- wt__remove)- opts="-h --help"- if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then- COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )- return 0- fi- case "${prev}" in- *)- COMPREPLY=()- ;;- esac- COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )- return 0- ;;- wt__switch)- opts="-c -b -x -f -h --create --base --execute --force --no-hooks --help <BRANCH>"- if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then- COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )- return 0- fi- case "${prev}" in- --base)- COMPREPLY=($(compgen -f "${cur}"))- return 0- ;;- -b)- COMPREPLY=($(compgen -f "${cur}"))- return 0- ;;- --execute)- COMPREPLY=($(compgen -f "${cur}"))- return 0- ;;- -x)- COMPREPLY=($(compgen -f "${cur}"))- return 0- ;;- *)- COMPREPLY=()- ;;- esac- COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )- return 0- ;;- esac-}--if [[ "${BASH_VERSINFO[0]}" -eq 4 && "${BASH_VERSINFO[1]}" -ge 4 || "${BASH_VERSINFO[0]}" -gt 4 ]]; then- complete -F _wt -o nosort -o bashdefault -o default wt-else- complete -F _wt -o bashdefault -o default wt-fi------- stderr -----diff --git a/tests/snapshots/integration__integration_tests__init__init_powershell.snap b/tests/snapshots/integration__integration_tests__init__init_powershell.snapdeleted file mode 100644index 4758590f7..000000000--- a/tests/snapshots/integration__integration_tests__init__init_powershell.snap+++ /dev/null@@ -1,85 +0,0 @@-----source: tests/integration_tests/init.rs-info:- program: wt- args:- - init- - powershell- env:- CLICOLOR_FORCE: "1"- GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"- GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"- GIT_CONFIG_GLOBAL: /dev/null- GIT_CONFIG_SYSTEM: /dev/null- GIT_EDITOR: ""- LANG: C- LC_ALL: C- SOURCE_DATE_EPOCH: "1704067200"-----success: false-exit_code: 1------ stdout ------# worktrunk shell integration for PowerShell--# Only initialize if wt is available-if (Get-Command wt -ErrorAction SilentlyContinue) {- # Helper function to parse wt output and handle directives- function _wt_exec {- param(- [Parameter(ValueFromRemainingArguments=$true)]- [string[]]$Arguments- )-- # Capture output and exit code- $output = & wt @Arguments 2>&1- $exitCode = $LASTEXITCODE-- # Parse output line by line- foreach ($line in $output) {- if ($line -match '^__WORKTRUNK_CD__(.+)$') {- # Extract path and change directory- Set-Location $matches[1]- } else {- # Regular output - write it- Write-Output $line- }- }-- # Return the exit code- return $exitCode- }-- # Override wt command to add --internal flag for switch, remove, and merge- function wt {- param(- [Parameter(ValueFromRemainingArguments=$true)]- [string[]]$Arguments- )-- if ($Arguments.Count -eq 0) {- & wt- return $LASTEXITCODE- }-- $subcommand = $Arguments[0]-- switch ($subcommand) {- { $_ -in @("switch", "remove", "merge") } {- # Commands that need --internal for directory change support- $restArgs = $Arguments[1..($Arguments.Count-1)]- $exitCode = _wt_exec $subcommand --internal @restArgs- return $exitCode- }- default {- # All other commands pass through directly- & wt @Arguments- return $LASTEXITCODE- }- }- }-}--# Static completions (commands and flags)------- stderr ------β [31mCompletion not yet supported for powershell[0mdiff --git a/tests/snapshots/integration__integration_tests__init__init_xonsh.snap b/tests/snapshots/integration__integration_tests__init__init_xonsh.snapdeleted file mode 100644index c0a7070b1..000000000--- a/tests/snapshots/integration__integration_tests__init__init_xonsh.snap+++ /dev/null@@ -1,70 +0,0 @@-----source: tests/integration_tests/init.rs-info:- program: wt- args:- - init- - xonsh- env:- CLICOLOR_FORCE: "1"- GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"- GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"- GIT_CONFIG_GLOBAL: /dev/null- GIT_CONFIG_SYSTEM: /dev/null- GIT_EDITOR: ""- LANG: C- LC_ALL: C- SOURCE_DATE_EPOCH: "1704067200"-----success: false-exit_code: 1------ stdout ------# worktrunk shell integration for xonsh--# Only initialize if wt is available-import shutil-if shutil.which("wt") is not None:- def _wt_exec(args):- """Helper function to parse wt output and handle directives"""- # Capture full output including return code- result = !(wt @(args))-- # Parse output line by line- if result.out:- for line in result.out.splitlines():- if line.startswith("__WORKTRUNK_CD__"):- # Extract path and change directory- path = line[17:] # Remove prefix- cd @(path)- else:- # Regular output - print it- print(line)-- # Return the exit code- return result.returncode-- def _wt_wrapper(args):- """Override wt command to add --internal flag for switch, remove, and merge"""- if not args:- # No arguments, just run wt- wt- return-- subcommand = args[0]-- if subcommand in ["switch", "remove", "merge"]:- # Commands that need --internal for directory change support- rest_args = args[1:]- return _wt_exec([subcommand, "--internal"] + rest_args)- else:- # All other commands pass through directly- result = !(wt @(args))- return result.returncode-- # Register the alias- aliases['wt'] = _wt_wrapper--# Static completions (commands and flags)------- stderr ------β [31mCompletion not yet supported for xonsh[0mdiff --git a/tests/snapshots/integration__integration_tests__init__init_zsh.snap b/tests/snapshots/integration__integration_tests__init__init_zsh.snapindex 8e5c92f8e..a73102de4 100644--- a/tests/snapshots/integration__integration_tests__init__init_zsh.snap+++ b/tests/snapshots/integration__integration_tests__init__init_zsh.snap@@ -152,6 +152,30 @@ _arguments "${_arguments_options[@]}" : \'--help[Print help]' \&& ret=0;;+(config)+_arguments "${_arguments_options[@]}" : \+'-h[Print help]' \+'--help[Print help]' \+":: :_wt__config_commands" \+"*::: :->config" \+&& ret=0++ case $state in+ (config)+ words=($line[1] "${words[@]}")+ (( CURRENT += 1 ))+ curcontext="${curcontext%:*:*}:wt-config-command-$line[1]:"+ case $line[1] in+ (list)+_arguments "${_arguments_options[@]}" : \+'-h[Print help]' \+'--help[Print help]' \+&& ret=0+;;+ esac+ ;;+esac+;;(list)_arguments "${_arguments_options[@]}" : \'--format=[Output format]:FORMAT:((table\:"Human-readable table format"@@ -226,6 +250,7 @@ _wt_commands() {local commands; commands=('init:Generate shell integration code' \'configure-shell:Configure shell by writing to config files' \+'config:Manage configuration' \'list:List all worktrees' \'switch:Switch to a worktree' \'remove:Finish current worktree, returning to primary if current' \@@ -246,6 +271,18 @@ _wt__completion_commands() {local commands; commands=()_describe -t commands 'wt completion commands' commands "$@"}+(( $+functions[_wt__config_commands] )) ||+_wt__config_commands() {+ local commands; commands=(+'list:List all configuration files and their locations' \+ )+ _describe -t commands 'wt config commands' commands "$@"+}+(( $+functions[_wt__config__list_commands] )) ||+_wt__config__list_commands() {+ local commands; commands=()+ _describe -t commands 'wt config list commands' commands "$@"+}(( $+functions[_wt__configure-shell_commands] )) ||_wt__configure-shell_commands() {local commands; commands=()