Skip to content

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

fix(output): use bash formatting for verbose expansion gutter (#1362)

Maximilian Roos9c3ca4bd7f7a
diff --git a/.claude/skills/writing-user-outputs/SKILL.md b/.claude/skills/writing-user-outputs/SKILL.md
index 1c3b83aa8..9d1692771 100644
--- a/.claude/skills/writing-user-outputs/SKILL.md
+++ b/.claude/skills/writing-user-outputs/SKILL.md
@@ -817,13 +817,17 @@ Shows template expansions and other details users might need for debugging confi
Format for template expansion:
```
○ Expanding name
- ┃ template → result
+ ┃ template (bash-highlighted)
+ ┃ → (dim)
+ ┃ result (bash-highlighted)
```
- **Info message** for header (`○` symbol, "Expanding" + bold name)
-- **Gutter** for quoted content (template → result)
-- Arrow `→` is dim
-- For multiline: template lines, dim `→` on its own line, result lines
+- **Bash gutter** for template and result (dim + syntax highlighting via
+ `format_bash_with_gutter`)
+- **Plain gutter** for dim `→` separator (bypasses syntax highlighter)
+- Template and result are always on separate gutter blocks from the arrow,
+ because the `→` can't go through the bash syntax highlighter
**`-vv` (debug):** Developer-facing logging output. MAY violate these guidelines.
Uses `log::debug!()` with structured format for deep debugging. Not intended for
diff --git a/src/config/expansion.rs b/src/config/expansion.rs
index 7e2cb1cd5..8234b1fba 100644
--- a/src/config/expansion.rs
+++ b/src/config/expansion.rs
@@ -18,7 +18,8 @@ use shell_escape::escape;
use crate::git::Repository;
use crate::path::to_posix_path;
use crate::styling::{
- eprintln, error_message, format_with_gutter, hint_message, info_message, verbosity,
+ eprintln, error_message, format_bash_with_gutter, format_with_gutter, hint_message,
+ info_message, verbosity,
};
/// Known template variables available in hook commands.
@@ -419,15 +420,12 @@ pub fn expand_template(
// Single atomic write to avoid interleaving in multi-threaded execution
if verbose == 1 {
let header = info_message(cformat!("Expanding <bold>{name}</>"));
- let content = if template.contains('\n') || result.contains('\n') {
- // Multiline: template lines, dim →, result lines
- cformat!("{template}\n<dim>→</>\n{result}")
- } else {
- // Single line: template → result
- cformat!("{template} <dim>→</> {result}")
- };
- let gutter = format_with_gutter(&content, None);
- eprintln!("{header}\n{gutter}");
+ // Format template and result as bash (dim + syntax highlighting),
+ // with a dim → separator that bypasses the syntax highlighter
+ let template_gutter = format_bash_with_gutter(template);
+ let arrow = format_with_gutter(&cformat!("<dim>→</>"), None);
+ let result_gutter = format_bash_with_gutter(&result);
+ eprintln!("{header}\n{template_gutter}\n{arrow}\n{result_gutter}");
}
Ok(result)
}
diff --git a/tests/snapshots/integration__integration_tests__config_show__deprecated_template_variables_verbose_shows_content.snap b/tests/snapshots/integration__integration_tests__config_show__deprecated_template_variables_verbose_shows_content.snap
index 41183f0e5..3135d752a 100644
--- a/tests/snapshots/integration__integration_tests__config_show__deprecated_template_variables_verbose_shows_content.snap
+++ b/tests/snapshots/integration__integration_tests__config_show__deprecated_template_variables_verbose_shows_content.snap
@@ -19,6 +19,7 @@ info:
LANG: C
LC_ALL: C
MOCK_CONFIG_DIR: "[MOCK_CONFIG_DIR]"
+ NO_COLOR: ""
PATH: "[PATH]"
PSModulePath: ""
RUST_LOG: warn
@@ -50,8 +51,14 @@ exit_code: 0
----- stderr -----
▲ User config has deprecated settings. Run wt config show for details or wt config update to apply updates
○ Expanding worktree-path
-  ../{{ main_worktree }}.{{ branch }} → ../repo.feature-a
+  ../{{ main_worktree }}.{{ branch }}
+  →
+  ../repo.feature-a
○ Expanding worktree-path
-  ../{{ main_worktree }}.{{ branch }} → ../repo.feature-b
+  ../{{ main_worktree }}.{{ branch }}
+  →
+  ../repo.feature-b
○ Expanding worktree-path
-  ../{{ main_worktree }}.{{ branch }} → ../repo.feature-c
+  ../{{ main_worktree }}.{{ branch }}
+  →
+  ../repo.feature-c
diff --git a/tests/snapshots/integration__integration_tests__post_start_commands__post_create_verbose_template_expansion.snap b/tests/snapshots/integration__integration_tests__post_start_commands__post_create_verbose_template_expansion.snap
index ff62776b6..40a992d84 100644
--- a/tests/snapshots/integration__integration_tests__post_start_commands__post_create_verbose_template_expansion.snap
+++ b/tests/snapshots/integration__integration_tests__post_start_commands__post_create_verbose_template_expansion.snap
@@ -45,9 +45,13 @@ exit_code: 0
----- stderr -----
○ Expanding worktree-path
-  ../{{ repo }}.{{ branch | sanitize }} → ../repo.verbose-hooks
+  ../{{ repo }}.{{ branch | sanitize }}
+  →
+  ../repo.verbose-hooks
○ Expanding project:setup
-  echo 'Setting up {{ branch | sanitize }} in {{ worktree_path }}' → echo 'Setting up verbose-hooks in _REPO_.verbose-hooks'
+  echo 'Setting up {{ branch | sanitize }} in {{ worktree_path }}'
+  →
+  echo 'Setting up verbose-hooks in _REPO_.verbose-hooks'
◎ Running post-create project:setup @ _REPO_.verbose-hooks
  echo 'Setting up verbose-hooks in _REPO_.verbose-hooks'
Setting up verbose-hooks in _REPO_.verbose-hooks
diff --git a/tests/snapshots/integration__integration_tests__post_start_commands__post_start_verbose_output.snap b/tests/snapshots/integration__integration_tests__post_start_commands__post_start_verbose_output.snap
index aa9cbfde1..3e4975728 100644
--- a/tests/snapshots/integration__integration_tests__post_start_commands__post_start_verbose_output.snap
+++ b/tests/snapshots/integration__integration_tests__post_start_commands__post_start_verbose_output.snap
@@ -45,12 +45,16 @@ exit_code: 0
----- stderr -----
○ Expanding worktree-path
-  {{ repo_path }}/../{{ repo }}.{{ branch | sanitize }} → _REPO_/../repo.feature
+  {{ repo_path }}/../{{ repo }}.{{ branch | sanitize }}
+  →
+  _REPO_/../repo.feature
✓ Created branch feature from main and worktree @ _REPO_.feature
↳ To customize worktree locations, run wt config create
▲ Cannot change directory — shell integration not installed
↳ To enable automatic cd, run wt config shell install
○ Expanding project:setup
-  echo 'verbose test' > verbose.txt → echo 'verbose test' > verbose.txt
+  echo 'verbose test' > verbose.txt
+  →
+  echo 'verbose test' > verbose.txt
◎ Running post-start project:setup @ _REPO_.feature
  echo 'verbose test' > verbose.txt
diff --git a/tests/snapshots/integration__integration_tests__switch__switch_execute_verbose_multiline_template.snap b/tests/snapshots/integration__integration_tests__switch__switch_execute_verbose_multiline_template.snap
index d075810e2..9fceae1d3 100644
--- a/tests/snapshots/integration__integration_tests__switch__switch_execute_verbose_multiline_template.snap
+++ b/tests/snapshots/integration__integration_tests__switch__switch_execute_verbose_multiline_template.snap
@@ -49,20 +49,22 @@ repo=repo
----- stderr -----
○ Expanding worktree-path
-  {{ repo_path }}/../{{ repo }}.{{ branch | sanitize }} → _REPO_/../repo.multiline-test
+  {{ repo_path }}/../{{ repo }}.{{ branch | sanitize }}
+  →
+  _REPO_/../repo.multiline-test
✓ Created branch multiline-test from main and worktree @ _REPO_.multiline-test
↳ To customize worktree locations, run wt config create
▲ Cannot change directory — shell integration not installed
↳ To enable automatic cd, run wt config shell install
○ Expanding --execute command
-  {% if branch %}
-  echo 'branch={{ branch }}'
-  echo 'repo={{ repo }}'
-  {% endif %}
+  {% if branch %}
+  echo 'branch={{ branch }}'
+  echo 'repo={{ repo }}'
+  {% endif %}
  →
- 
-  echo 'branch=multiline-test'
-  echo 'repo=repo'
+  
+  echo 'branch=multiline-test'
+  echo 'repo=repo'
◎ Executing (--execute) @ _REPO_.multiline-test:
  
  echo 'branch=multiline-test'
diff --git a/tests/snapshots/integration__integration_tests__switch__switch_execute_verbose_template.snap b/tests/snapshots/integration__integration_tests__switch__switch_execute_verbose_template.snap
index 0af455394..40ae57922 100644
--- a/tests/snapshots/integration__integration_tests__switch__switch_execute_verbose_template.snap
+++ b/tests/snapshots/integration__integration_tests__switch__switch_execute_verbose_template.snap
@@ -48,12 +48,16 @@ branch=verbose-test
----- stderr -----
○ Expanding worktree-path
-  {{ repo_path }}/../{{ repo }}.{{ branch | sanitize }} → _REPO_/../repo.verbose-test
+  {{ repo_path }}/../{{ repo }}.{{ branch | sanitize }}
+  →
+  _REPO_/../repo.verbose-test
✓ Created branch verbose-test from main and worktree @ _REPO_.verbose-test
↳ To customize worktree locations, run wt config create
▲ Cannot change directory — shell integration not installed
↳ To enable automatic cd, run wt config shell install
○ Expanding --execute command
-  echo 'branch={{ branch }}' → echo 'branch=verbose-test'
+  echo 'branch={{ branch }}'
+  →
+  echo 'branch=verbose-test'
◎ Executing (--execute) @ _REPO_.verbose-test:
  echo 'branch=verbose-test'