Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
Add template variable support to --execute command (#581)
Maximilian Roos9a92f8170259
diff --git a/.claude-plugin/skills/worktrunk/reference/switch.md b/.claude-plugin/skills/worktrunk/reference/switch.mdindex 47f2df4ea..cfb9e695f 100644--- a/.claude-plugin/skills/worktrunk/reference/switch.md+++ b/.claude-plugin/skills/worktrunk/reference/switch.md@@ -73,7 +73,7 @@ Usage: <b><span class=c>wt switch</span></b> <span class=c>[OPTIONS]</span> <spaAdditional arguments for --execute command (after --)Arguments after <b>--</b> are appended to the execute command. Each argument- is POSIX shell-escaped before appending.+ is expanded for templates, then POSIX shell-escaped.<b><span class=g>Options:</span></b><b><span class=c>-c</span></b>, <b><span class=c>--create</span></b>@@ -91,6 +91,10 @@ Usage: <b><span class=c>wt switch</span></b> <span class=c>[OPTIONS]</span> <spafull terminal control. Useful for launching editors, AI agents, orother interactive tools.+ Supports ]8;;@/hook.md#template-variables\<u>hook template variables]8;;\</u> (<b>{{ branch }}</b>, <b>{{ worktree_path }}</b>,+ etc.) and filters. <b>{{ base }}</b> and <b>{{ base_worktree_path }}</b> require+ --create.+Especially useful with shell aliases:<b>alias wsc='wt switch --create -x claude'</b>@@ -100,6 +104,10 @@ Usage: <b><span class=c>wt switch</span></b> <span class=c>[OPTIONS]</span> <spaArguments after <b>--</b> are passed to the command, so <b>wsc feature -- 'Fix</b>GH #322' runs <b>claude 'Fix GH #322'</b>, starting Claude with a prompt.+ Template example: <b>-x 'code {{ worktree_path }}'</b> opens VS Code at the+ worktree, <b>-x 'tmux new -s {{ branch | sanitize }}'</b> starts a tmux+ session named after the branch.+<b><span class=c>-y</span></b>, <b><span class=c>--yes</span></b>Skip approval promptsdiff --git a/docs/content/switch.md b/docs/content/switch.mdindex db7f1ffa4..b8c26394b 100644--- a/docs/content/switch.md+++ b/docs/content/switch.md@@ -96,7 +96,7 @@ Usage: <b><span class=c>wt switch</span></b> <span class=c>[OPTIONS]</span> <spaAdditional arguments for --execute command (after --)Arguments after <b>--</b> are appended to the execute command. Each argument- is POSIX shell-escaped before appending.+ is expanded for templates, then POSIX shell-escaped.<b><span class=g>Options:</span></b><b><span class=c>-c</span></b>, <b><span class=c>--create</span></b>@@ -114,6 +114,10 @@ Usage: <b><span class=c>wt switch</span></b> <span class=c>[OPTIONS]</span> <spafull terminal control. Useful for launching editors, AI agents, orother interactive tools.+ Supports ]8;;@/hook.md#template-variables\<u>hook template variables]8;;\</u> (<b>{{ branch }}</b>, <b>{{ worktree_path }}</b>,+ etc.) and filters. <b>{{ base }}</b> and <b>{{ base_worktree_path }}</b> require+ --create.+Especially useful with shell aliases:<b>alias wsc='wt switch --create -x claude'</b>@@ -123,6 +127,10 @@ Usage: <b><span class=c>wt switch</span></b> <span class=c>[OPTIONS]</span> <spaArguments after <b>--</b> are passed to the command, so <b>wsc feature -- 'Fix</b>GH #322' runs <b>claude 'Fix GH #322'</b>, starting Claude with a prompt.+ Template example: <b>-x 'code {{ worktree_path }}'</b> opens VS Code at the+ worktree, <b>-x 'tmux new -s {{ branch | sanitize }}'</b> starts a tmux+ session named after the branch.+<b><span class=c>-y</span></b>, <b><span class=c>--yes</span></b>Skip approval promptsdiff --git a/src/cli/mod.rs b/src/cli/mod.rsindex 35e7726ba..3be666465 100644--- a/src/cli/mod.rs+++ b/src/cli/mod.rs@@ -333,6 +333,10 @@ To change which branch a worktree is on, use `git switch` inside that worktree./// it full terminal control. Useful for launching editors, AI agents,/// or other interactive tools.///+ /// Supports [hook template variables](@/hook.md#template-variables)+ /// (`{{ branch }}`, `{{ worktree_path }}`, etc.) and filters.+ /// `{{ base }}` and `{{ base_worktree_path }}` require `--create`.+ ////// Especially useful with shell aliases:////// ```sh@@ -344,13 +348,17 @@ To change which branch a worktree is on, use `git switch` inside that worktree./// Code. Arguments after `--` are passed to the command, so/// `wsc feature -- 'Fix GH #322'` runs `claude 'Fix GH #322'`,/// starting Claude with a prompt.+ ///+ /// Template example: `-x 'code {{ worktree_path }}'` opens VS Code+ /// at the worktree, `-x 'tmux new -s {{ branch | sanitize }}'` starts+ /// a tmux session named after the branch.#[arg(short = 'x', long)]execute: Option<String>,/// Additional arguments for --execute command (after --)////// Arguments after `--` are appended to the execute command.- /// Each argument is POSIX shell-escaped before appending.+ /// Each argument is expanded for templates, then POSIX shell-escaped.#[arg(last = true, requires = "execute")]execute_args: Vec<String>,diff --git a/src/main.rs b/src/main.rsindex ef27726e9..bb234abbc 100644--- a/src/main.rs+++ b/src/main.rs@@ -3,7 +3,7 @@ use clap::FromArgMatches;use color_print::cformat;use std::path::PathBuf;use std::process;-use worktrunk::config::{WorktrunkConfig, set_config_path};+use worktrunk::config::{WorktrunkConfig, expand_template, set_config_path};use worktrunk::git::{Repository, exit_code, set_base_path};use worktrunk::path::format_path_for_display;use worktrunk::shell::extract_filename_from_path;@@ -26,7 +26,7 @@ mod verbose_log;pub use crate::cli::OutputFormat;-use commands::command_executor::CommandContext;+use commands::command_executor::{CommandContext, build_hook_context};#[cfg(unix)]use commands::handle_select;use commands::worktree::{SwitchResult, handle_push};@@ -1405,6 +1405,26 @@ fn main() {output::prompt_shell_integration(&mut config, &binary_name(), skip_prompt);}+ // Build extra vars for base branch context (used by both hooks and --execute)+ // "base" is the branch we branched from when creating a new worktree.+ // For existing worktrees, there's no base concept.+ let (base_branch, base_worktree_path): (Option<&str>, Option<&str>) = match &result+ {+ SwitchResult::Created {+ base_branch,+ base_worktree_path,+ ..+ } => (base_branch.as_deref(), base_worktree_path.as_deref()),+ SwitchResult::Existing(_) | SwitchResult::AlreadyAt(_) => (None, None),+ };+ let extra_vars: Vec<(&str, &str)> = [+ base_branch.map(|b| ("base", b)),+ base_worktree_path.map(|p| ("base_worktree_path", p)),+ ]+ .into_iter()+ .flatten()+ .collect();+// Spawn background hooks after success message// - post-switch: runs on ALL switches (shows "@ path" when shell won't be there)// - post-start: runs only when creating a NEW worktree@@ -1420,26 +1440,6 @@ fn main() {yes,);- // Build extra vars for base branch context- // "base" is the branch we branched from when creating a new worktree.- // For existing worktrees, there's no base concept.- let (base_branch, base_worktree_path): (Option<&str>, Option<&str>) =- match &result {- SwitchResult::Created {- base_branch,- base_worktree_path,- ..- } => (base_branch.as_deref(), base_worktree_path.as_deref()),- SwitchResult::Existing(_) | SwitchResult::AlreadyAt(_) => (None, None),- };- let extra_vars: Vec<(&str, &str)> = [- base_branch.map(|b| ("base", b)),- base_worktree_path.map(|p| ("base_worktree_path", p)),- ]- .into_iter()- .flatten()- .collect();-// Post-switch runs first (immediate "I'm here" signal)ctx.spawn_post_switch_commands(&extra_vars, hooks_display_path.as_deref())?;@@ -1452,15 +1452,46 @@ fn main() {// Execute user command after post-start hooks have been spawned// Note: execute_args requires execute via clap's `requires` attributeif let Some(cmd) = execute {+ // Build template context for expansion (includes base vars when creating)+ let repo = Repository::current()?;+ let repo_root = repo.worktree_base().context("Failed to get repo root")?;+ let ctx = CommandContext::new(+ &repo,+ &config,+ Some(&branch_info.branch),+ result.path(),+ &repo_root,+ yes,+ );+ let template_vars = build_hook_context(&ctx, &extra_vars);+ let vars: std::collections::HashMap<&str, &str> = template_vars+ .iter()+ .map(|(k, v)| (k.as_str(), v.as_str()))+ .collect();++ // Expand template variables in command (shell_escape: true for safety)+ let expanded_cmd = expand_template(&cmd, &vars, true).map_err(|e| {+ anyhow::anyhow!("Failed to expand --execute template: {}", e)+ })?;+// Append any trailing args (after --) to the execute command+ // Each arg is also expanded, then shell-escapedlet full_cmd = if execute_args.is_empty() {- cmd+ expanded_cmd} else {- let escaped_args: Vec<_> = execute_args+ let expanded_args: Result<Vec<_>, _> = execute_args+ .iter()+ .map(|arg| {+ expand_template(arg, &vars, false).map_err(|e| {+ anyhow::anyhow!("Failed to expand argument template: {}", e)+ })+ })+ .collect();+ let escaped_args: Vec<_> = expanded_args?.iter().map(|arg| shlex::try_quote(arg).unwrap_or(arg.into()).into_owned()).collect();- format!("{} {}", cmd, escaped_args.join(" "))+ format!("{} {}", expanded_cmd, escaped_args.join(" "))};execute_user_command(&full_cmd)?;}diff --git a/tests/integration_tests/switch.rs b/tests/integration_tests/switch.rsindex c49d3b772..4fee1adc0 100644--- a/tests/integration_tests/switch.rs+++ b/tests/integration_tests/switch.rs@@ -306,6 +306,110 @@ fn test_switch_execute_multiline(repo: TestRepo) {&["--create", "multiline-test", "--execute", multiline_cmd],);}++// Execute template expansion tests+#[rstest]+fn test_switch_execute_template_branch(repo: TestRepo) {+ // Test that {{ branch }} is expanded in --execute command+ snapshot_switch(+ "switch_execute_template_branch",+ &repo,+ &[+ "--create",+ "template-test",+ "--execute",+ "echo 'branch={{ branch }}'",+ ],+ );+}++#[rstest]+fn test_switch_execute_template_base(repo: TestRepo) {+ // Test that {{ base }} is available when creating with --create+ snapshot_switch(+ "switch_execute_template_base",+ &repo,+ &[+ "--create",+ "from-main",+ "--base",+ "main",+ "--execute",+ "echo 'base={{ base }}'",+ ],+ );+}++#[rstest]+fn test_switch_execute_template_base_without_create(mut repo: TestRepo) {+ // Test that {{ base }} is empty when switching to existing worktree (no --create)+ repo.add_worktree("existing");+ snapshot_switch(+ "switch_execute_template_base_without_create",+ &repo,+ &["existing", "--execute", "echo 'base={{ base }}'"],+ );+}++#[rstest]+fn test_switch_execute_template_with_filter(repo: TestRepo) {+ // Test that filters work ({{ branch | sanitize }})+ snapshot_switch(+ "switch_execute_template_with_filter",+ &repo,+ &[+ "--create",+ "feature/with-slash",+ "--execute",+ "echo 'sanitized={{ branch | sanitize }}'",+ ],+ );+}++#[rstest]+fn test_switch_execute_template_shell_escape(repo: TestRepo) {+ // Test that shell metacharacters in branch names are escaped+ // Without escaping, this would execute `id` as a separate command+ snapshot_switch(+ "switch_execute_template_shell_escape",+ &repo,+ &["--create", "feat;id", "--execute", "echo {{ branch }}"],+ );+}++#[rstest]+fn test_switch_execute_template_worktree_path(repo: TestRepo) {+ // Test that {{ worktree_path }} is expanded+ snapshot_switch(+ "switch_execute_template_worktree_path",+ &repo,+ &[+ "--create",+ "path-test",+ "--execute",+ "echo 'path={{ worktree_path }}'",+ ],+ );+}++#[rstest]+fn test_switch_execute_template_in_args(repo: TestRepo) {+ // Test that templates are expanded in trailing args (after --)+ snapshot_switch(+ "switch_execute_template_in_args",+ &repo,+ &[+ "--create",+ "args-test",+ "--execute",+ "echo",+ "--",+ "branch={{ branch }}",+ "repo={{ repo }}",+ ],+ );+}+// --no-verify flag tests#[rstest]fn test_switch_no_config_commands_execute_still_runs(repo: TestRepo) {diff --git a/tests/snapshots/integration__integration_tests__help__help_switch_long.snap b/tests/snapshots/integration__integration_tests__help__help_switch_long.snapindex 1e934c20e..a5ca5798f 100644--- a/tests/snapshots/integration__integration_tests__help__help_switch_long.snap+++ b/tests/snapshots/integration__integration_tests__help__help_switch_long.snap@@ -33,7 +33,7 @@ Usage: [1m[36mwt switch[0m [36m[OPTIONS][0m [36m<BRANCH>[0m [1m[36m[--[36m[EXECUTE_ARGS]...Additional arguments for --execute command (after --)- Arguments after [1m--[0m are appended to the execute command. Each argument is POSIX shell-escaped before appending.+ Arguments after [1m--[0m are appended to the execute command. Each argument is expanded for templates, then POSIX shell-escaped.[1m[32mOptions:[1m[36m-c[0m, [1m[36m--create@@ -49,12 +49,16 @@ Usage: [1m[36mwt switch[0m [36m[OPTIONS][0m [36m<BRANCH>[0m [1m[36m[--Replaces the wt process with the command after switching, giving it full terminal control. Useful for launching editors, AI agents, or other interactive tools.+ Supports ]8;;@/hook.md#template-variables\[4mhook template variables]8;;\[0m ([1m{{ branch }}[0m, [1m{{ worktree_path }}[0m, etc.) and filters. [1m{{ base }}[0m and [1m{{ base_worktree_path }}[0m require [1m--create[0m.+Especially useful with shell aliases:[1m[1malias wsc='wt switch --create -x claude'[1mwsc feature-branch -- 'Fix GH #322'Then [1mwsc feature-branch[0m creates the worktree and launches Claude Code. Arguments after [1m--[0m are passed to the command, so [1mwsc feature -- 'Fix GH #322'[0m runs [1mclaude 'Fix GH #322'[0m, starting Claude with a prompt.++ Template example: [1m-x 'code {{ worktree_path }}'[0m opens VS Code at the worktree, [1m-x 'tmux new -s {{ branch | sanitize }}'[0m starts a tmux session named after the branch.[1m[36m-y[0m, [1m[36m--yesSkip approval promptsdiff --git a/tests/snapshots/integration__integration_tests__switch__switch_execute_template_base.snap b/tests/snapshots/integration__integration_tests__switch__switch_execute_template_base.snapnew file mode 100644index 000000000..42c250c00--- /dev/null+++ b/tests/snapshots/integration__integration_tests__switch__switch_execute_template_base.snap@@ -0,0 +1,46 @@+---+source: tests/integration_tests/switch.rs+info:+ program: wt+ args:+ - switch+ - "--create"+ - from-main+ - "--base"+ - main+ - "--execute"+ - "echo 'base={{ base }}'"+ env:+ APPDATA: "[TEST_CONFIG_HOME]"+ CLICOLOR_FORCE: "1"+ COLUMNS: "500"+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"+ GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"+ GIT_CONFIG_SYSTEM: /dev/null+ GIT_EDITOR: ""+ GIT_TERMINAL_PROMPT: "0"+ HOME: "[TEST_HOME]"+ LANG: C+ LC_ALL: C+ PATH: "[PATH]"+ RUST_LOG: warn+ SOURCE_DATE_EPOCH: "1735776000"+ TERM: alacritty+ USERPROFILE: "[TEST_HOME]"+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"+ WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"+---+success: true+exit_code: 0+----- stdout -----+base=main++----- stderr -----+[32m✓[39m [32mCreated branch [1mfrom-main[22m and worktree from [1mmain[22m @ [1m_REPO_.from-main[22m[39m+[2m↳[22m [2mCustomize worktree locations: [90mwt config create[39m[22m+[33m▲[39m [33mExecuting [1mecho 'base={{ base }}'[22m @ [1m_REPO_.from-main[22m, but shell directory unchanged — shell integration not installed[39m+[2m↳[22m [2mTo enable automatic cd, run [90mwt config shell install[39m[22m+[36m◎[39m [36mExecuting (--execute):[39m+[107m [0m [2m[0m[2m[34mecho[0m[2m [0m[2m[32m'base=main'[0m[2mdiff --git a/tests/snapshots/integration__integration_tests__switch__switch_execute_template_base_without_create.snap b/tests/snapshots/integration__integration_tests__switch__switch_execute_template_base_without_create.snapnew file mode 100644index 000000000..d47b9dfe6--- /dev/null+++ b/tests/snapshots/integration__integration_tests__switch__switch_execute_template_base_without_create.snap@@ -0,0 +1,41 @@+---+source: tests/integration_tests/switch.rs+info:+ program: wt+ args:+ - switch+ - existing+ - "--execute"+ - "echo 'base={{ base }}'"+ env:+ APPDATA: "[TEST_CONFIG_HOME]"+ CLICOLOR_FORCE: "1"+ COLUMNS: "500"+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"+ GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"+ GIT_CONFIG_SYSTEM: /dev/null+ GIT_EDITOR: ""+ GIT_TERMINAL_PROMPT: "0"+ HOME: "[TEST_HOME]"+ LANG: C+ LC_ALL: C+ PATH: "[PATH]"+ RUST_LOG: warn+ SOURCE_DATE_EPOCH: "1735776000"+ TERM: alacritty+ USERPROFILE: "[TEST_HOME]"+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"+ WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"+---+success: true+exit_code: 0+----- stdout -----+base=++----- stderr -----+[33m▲[39m [33mExecuting [1mecho 'base={{ base }}'[22m @ [1m_REPO_.existing[22m, but shell directory unchanged — shell integration not installed[39m+[2m↳[22m [2mTo enable automatic cd, run [90mwt config shell install[39m[22m+[36m◎[39m [36mExecuting (--execute):[39m+[107m [0m [2m[0m[2m[34mecho[0m[2m [0m[2m[32m'base='[0m[2mdiff --git a/tests/snapshots/integration__integration_tests__switch__switch_execute_template_branch.snap b/tests/snapshots/integration__integration_tests__switch__switch_execute_template_branch.snapnew file mode 100644index 000000000..375f3a3ac--- /dev/null+++ b/tests/snapshots/integration__integration_tests__switch__switch_execute_template_branch.snap@@ -0,0 +1,44 @@+---+source: tests/integration_tests/switch.rs+info:+ program: wt+ args:+ - switch+ - "--create"+ - template-test+ - "--execute"+ - "echo 'branch={{ branch }}'"+ env:+ APPDATA: "[TEST_CONFIG_HOME]"+ CLICOLOR_FORCE: "1"+ COLUMNS: "500"+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"+ GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"+ GIT_CONFIG_SYSTEM: /dev/null+ GIT_EDITOR: ""+ GIT_TERMINAL_PROMPT: "0"+ HOME: "[TEST_HOME]"+ LANG: C+ LC_ALL: C+ PATH: "[PATH]"+ RUST_LOG: warn+ SOURCE_DATE_EPOCH: "1735776000"+ TERM: alacritty+ USERPROFILE: "[TEST_HOME]"+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"+ WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"+---+success: true+exit_code: 0+----- stdout -----+branch=template-test++----- stderr -----+[32m✓[39m [32mCreated branch [1mtemplate-test[22m and worktree from [1mmain[22m @ [1m_REPO_.template-test[22m[39m+[2m↳[22m [2mCustomize worktree locations: [90mwt config create[39m[22m+[33m▲[39m [33mExecuting [1mecho 'branch={{ branch }}'[22m @ [1m_REPO_.template-test[22m, but shell directory unchanged — shell integration not installed[39m+[2m↳[22m [2mTo enable automatic cd, run [90mwt config shell install[39m[22m+[36m◎[39m [36mExecuting (--execute):[39m+[107m [0m [2m[0m[2m[34mecho[0m[2m [0m[2m[32m'branch=template-test'[0m[2mdiff --git a/tests/snapshots/integration__integration_tests__switch__switch_execute_template_in_args.snap b/tests/snapshots/integration__integration_tests__switch__switch_execute_template_in_args.snapnew file mode 100644index 000000000..2097f3abe--- /dev/null+++ b/tests/snapshots/integration__integration_tests__switch__switch_execute_template_in_args.snap@@ -0,0 +1,47 @@+---+source: tests/integration_tests/switch.rs+info:+ program: wt+ args:+ - switch+ - "--create"+ - args-test+ - "--execute"+ - echo+ - "--"+ - "branch={{ branch }}"+ - "repo={{ repo }}"+ env:+ APPDATA: "[TEST_CONFIG_HOME]"+ CLICOLOR_FORCE: "1"+ COLUMNS: "500"+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"+ GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"+ GIT_CONFIG_SYSTEM: /dev/null+ GIT_EDITOR: ""+ GIT_TERMINAL_PROMPT: "0"+ HOME: "[TEST_HOME]"+ LANG: C+ LC_ALL: C+ PATH: "[PATH]"+ RUST_LOG: warn+ SOURCE_DATE_EPOCH: "1735776000"+ TERM: alacritty+ USERPROFILE: "[TEST_HOME]"+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"+ WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"+---+success: true+exit_code: 0+----- stdout -----+branch=args-test repo=repo++----- stderr -----+[32m✓[39m [32mCreated branch [1margs-test[22m and worktree from [1mmain[22m @ [1m_REPO_.args-test[22m[39m+[2m↳[22m [2mCustomize worktree locations: [90mwt config create[39m[22m+[33m▲[39m [33mExecuting [1mecho[22m @ [1m_REPO_.args-test[22m, but shell directory unchanged — shell integration not installed[39m+[2m↳[22m [2mTo enable automatic cd, run [90mwt config shell install[39m[22m+[36m◎[39m [36mExecuting (--execute):[39m+[107m [0m [2m[0m[2m[34mecho[0m[2m [0m[2m[32m'branch=args-test'[0m[2m [0m[2m[32m'repo=repo'[0m[2mdiff --git a/tests/snapshots/integration__integration_tests__switch__switch_execute_template_shell_escape.snap b/tests/snapshots/integration__integration_tests__switch__switch_execute_template_shell_escape.snapnew file mode 100644index 000000000..c31d856ae--- /dev/null+++ b/tests/snapshots/integration__integration_tests__switch__switch_execute_template_shell_escape.snap@@ -0,0 +1,44 @@+---+source: tests/integration_tests/switch.rs+info:+ program: wt+ args:+ - switch+ - "--create"+ - feat;id+ - "--execute"+ - "echo {{ branch }}"+ env:+ APPDATA: "[TEST_CONFIG_HOME]"+ CLICOLOR_FORCE: "1"+ COLUMNS: "500"+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"+ GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"+ GIT_CONFIG_SYSTEM: /dev/null+ GIT_EDITOR: ""+ GIT_TERMINAL_PROMPT: "0"+ HOME: "[TEST_HOME]"+ LANG: C+ LC_ALL: C+ PATH: "[PATH]"+ RUST_LOG: warn+ SOURCE_DATE_EPOCH: "1735776000"+ TERM: alacritty+ USERPROFILE: "[TEST_HOME]"+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"+ WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"+---+success: true+exit_code: 0+----- stdout -----+feat;id++----- stderr -----+[32m✓[39m [32mCreated branch [1mfeat;id[22m and worktree from [1mmain[22m @ [1m_REPO_.feat;id[22m[39m+[2m↳[22m [2mCustomize worktree locations: [90mwt config create[39m[22m+[33m▲[39m [33mExecuting [1mecho {{ branch }}[22m @ [1m_REPO_.feat;id[22m, but shell directory unchanged — shell integration not installed[39m+[2m↳[22m [2mTo enable automatic cd, run [90mwt config shell install[39m[22m+[36m◎[39m [36mExecuting (--execute):[39m+[107m [0m [2m[0m[2m[34mecho[0m[2m [0m[2m[32m'feat;id'[0m[2mdiff --git a/tests/snapshots/integration__integration_tests__switch__switch_execute_template_with_filter.snap b/tests/snapshots/integration__integration_tests__switch__switch_execute_template_with_filter.snapnew file mode 100644index 000000000..4384dc902--- /dev/null+++ b/tests/snapshots/integration__integration_tests__switch__switch_execute_template_with_filter.snap@@ -0,0 +1,44 @@+---+source: tests/integration_tests/switch.rs+info:+ program: wt+ args:+ - switch+ - "--create"+ - feature/with-slash+ - "--execute"+ - "echo 'sanitized={{ branch | sanitize }}'"+ env:+ APPDATA: "[TEST_CONFIG_HOME]"+ CLICOLOR_FORCE: "1"+ COLUMNS: "500"+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"+ GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"+ GIT_CONFIG_SYSTEM: /dev/null+ GIT_EDITOR: ""+ GIT_TERMINAL_PROMPT: "0"+ HOME: "[TEST_HOME]"+ LANG: C+ LC_ALL: C+ PATH: "[PATH]"+ RUST_LOG: warn+ SOURCE_DATE_EPOCH: "1735776000"+ TERM: alacritty+ USERPROFILE: "[TEST_HOME]"+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"+ WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"+---+success: true+exit_code: 0+----- stdout -----+sanitized=feature-with-slash++----- stderr -----+[32m✓[39m [32mCreated branch [1mfeature/with-slash[22m and worktree from [1mmain[22m @ [1m_REPO_.feature-with-slash[22m[39m+[2m↳[22m [2mCustomize worktree locations: [90mwt config create[39m[22m+[33m▲[39m [33mExecuting [1mecho 'sanitized={{ branch | sanitize }}'[22m @ [1m_REPO_.feature-with-slash[22m, but shell directory unchanged — shell integration not installed[39m+[2m↳[22m [2mTo enable automatic cd, run [90mwt config shell install[39m[22m+[36m◎[39m [36mExecuting (--execute):[39m+[107m [0m [2m[0m[2m[34mecho[0m[2m [0m[2m[32m'sanitized=feature-with-slash'[0m[2mdiff --git a/tests/snapshots/integration__integration_tests__switch__switch_execute_template_worktree_path.snap b/tests/snapshots/integration__integration_tests__switch__switch_execute_template_worktree_path.snapnew file mode 100644index 000000000..9c5bb29ce--- /dev/null+++ b/tests/snapshots/integration__integration_tests__switch__switch_execute_template_worktree_path.snap@@ -0,0 +1,44 @@+---+source: tests/integration_tests/switch.rs+info:+ program: wt+ args:+ - switch+ - "--create"+ - path-test+ - "--execute"+ - "echo 'path={{ worktree_path }}'"+ env:+ APPDATA: "[TEST_CONFIG_HOME]"+ CLICOLOR_FORCE: "1"+ COLUMNS: "500"+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"+ GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"+ GIT_CONFIG_SYSTEM: /dev/null+ GIT_EDITOR: ""+ GIT_TERMINAL_PROMPT: "0"+ HOME: "[TEST_HOME]"+ LANG: C+ LC_ALL: C+ PATH: "[PATH]"+ RUST_LOG: warn+ SOURCE_DATE_EPOCH: "1735776000"+ TERM: alacritty+ USERPROFILE: "[TEST_HOME]"+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"+ WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"+---+success: true+exit_code: 0+----- stdout -----+path=_REPO_.path-test++----- stderr -----+[32m✓[39m [32mCreated branch [1mpath-test[22m and worktree from [1mmain[22m @ [1m_REPO_.path-test[22m[39m+[2m↳[22m [2mCustomize worktree locations: [90mwt config create[39m[22m+[33m▲[39m [33mExecuting [1mecho 'path={{ worktree_path }}'[22m @ [1m_REPO_.path-test[22m, but shell directory unchanged — shell integration not installed[39m+[2m↳[22m [2mTo enable automatic cd, run [90mwt config shell install[39m[22m+[36m◎[39m [36mExecuting (--execute):[39m+[107m [0m [2m[0m[2m[34mecho[0m[2m [0m[2m[32m'path=_REPO_.path-test'[0m[2m