Skip to content

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

fix: strip `$ ` prompt from terminal help for copy-paste (#1992)

Maximilian Roos518e4c31c257
diff --git a/src/md_help.rs b/src/md_help.rs
index 61626024b..7f952d894 100644
--- a/src/md_help.rs
+++ b/src/md_help.rs
@@ -75,7 +75,17 @@ pub(crate) fn render_markdown_in_help_with_width(help: &str, width: Option<usize
let content = code_block_lines.join("\n");
let formatted = match code_block_lang.as_str() {
"toml" => format_toml(&content),
- "console" | "bash" | "sh" => format_bash_with_gutter(&content),
+ "console" => {
+ // Strip `$ ` prompt from console blocks for copy-paste.
+ // The prefix is preserved in source for web docs.
+ let stripped = content
+ .lines()
+ .map(|l| l.strip_prefix("$ ").unwrap_or(l))
+ .collect::<Vec<_>>()
+ .join("\n");
+ format_bash_with_gutter(&stripped)
+ }
+ "bash" | "sh" => format_bash_with_gutter(&content),
_ => {
// Dim the content before adding gutter (format_with_gutter
// doesn't style text; bash/toml formatters handle their own)
@@ -576,6 +586,19 @@ mod tests {
");
}
+ #[test]
+ fn test_render_markdown_in_help_console_strips_dollar() {
+ // Console blocks strip `$ ` for copy-paste; web docs keep it
+ let result = render_markdown_in_help("```console\n$ wt step deploy\n$ wt list\n```");
+ let stripped = ansi_str::AnsiStr::ansi_strip(&result);
+ assert!(
+ !stripped.contains("$ "),
+ "terminal output should not contain '$ ' prompt: {stripped}"
+ );
+ assert!(stripped.contains("wt step deploy"));
+ assert!(stripped.contains("wt list"));
+ }
+
#[test]
fn test_render_markdown_in_help_code_block() {
let result = render_markdown_in_help("```\ncode here\n```\nafter");
diff --git a/tests/snapshots/integration__integration_tests__help__help_config_long.snap b/tests/snapshots/integration__integration_tests__help__help_config_long.snap
index f834bcc97..ca747d898 100644
--- a/tests/snapshots/integration__integration_tests__help__help_config_long.snap
+++ b/tests/snapshots/integration__integration_tests__help__help_config_long.snap
@@ -64,19 +64,19 @@ Usage: wt config [OPTIONS] <COMMAND>
Install shell integration (required for directory switching):
-  $ wt config shell install
+  wt config shell install
Create user config file with documented examples:
-  $ wt config create
+  wt config create
Create project config file (.config/wt.toml) for hooks:
-  $ wt config create --project
+  wt config create --project
Show current configuration and file locations:
-  $ wt config show
+  wt config show
Configuration files
@@ -413,7 +413,7 @@ Aliases defined here are shared with teammates. For personal aliases, use the us
Worktrunk needs shell integration to change directories when switching worktrees. Install with:
-  $ wt config shell install
+  wt config shell install
For manual setup, see wt config shell init --help.
@@ -447,7 +447,7 @@ Note the single underscore after WORKTRUNK and double underscores betwee
Override the LLM command in CI to use a mock:
-  $ WORKTRUNK_COMMIT__GENERATION__COMMAND="echo 'test: automated commit'" wt merge
+  WORKTRUNK_COMMIT__GENERATION__COMMAND="echo 'test: automated commit'" wt merge
Other environment variables
diff --git a/tests/snapshots/integration__integration_tests__help__help_config_show.snap b/tests/snapshots/integration__integration_tests__help__help_config_show.snap
index cf65b5f76..4597a5cd1 100644
--- a/tests/snapshots/integration__integration_tests__help__help_config_show.snap
+++ b/tests/snapshots/integration__integration_tests__help__help_config_show.snap
@@ -63,7 +63,7 @@ If a config file doesn't exist, shows defaults that would be used.
Use --full to run diagnostic checks:
-  $ wt config show --full
+  wt config show --full
This tests:
- CI tool status β€” Whether gh (GitHub) or glab (GitLab) is installed and authenticated
diff --git a/tests/snapshots/integration__integration_tests__help__help_config_state.snap b/tests/snapshots/integration__integration_tests__help__help_config_state.snap
index fb1614ea7..49afcebf2 100644
--- a/tests/snapshots/integration__integration_tests__help__help_config_state.snap
+++ b/tests/snapshots/integration__integration_tests__help__help_config_state.snap
@@ -76,22 +76,22 @@ State is stored in .git/ (config entries and log files), separate from c
Examples
Get the default branch:
-  $ wt config state default-branch
+  wt config state default-branch
Set the default branch manually:
-  $ wt config state default-branch set main
+  wt config state default-branch set main
Set a marker for current branch:
-  $ wt config state marker set 🚧
+  wt config state marker set 🚧
Store arbitrary data:
-  $ wt config state vars set env=staging
+  wt config state vars set env=staging
Clear all CI status cache:
-  $ wt config state ci-status clear --all
+  wt config state ci-status clear --all
Show all stored state:
-  $ wt config state get
+  wt config state get
Clear all stored state:
-  $ wt config state clear
+  wt config state clear
diff --git a/tests/snapshots/integration__integration_tests__help__help_config_state_default_branch.snap b/tests/snapshots/integration__integration_tests__help__help_config_state_default_branch.snap
index 9c886754f..727e12073 100644
--- a/tests/snapshots/integration__integration_tests__help__help_config_state_default_branch.snap
+++ b/tests/snapshots/integration__integration_tests__help__help_config_state_default_branch.snap
@@ -59,7 +59,7 @@ Usage: wt config state default-branch [OPTIONS] [COMM
Useful in scripts to avoid hardcoding main or master:
-  $ git rebase $(wt config state default-branch)
+  git rebase $(wt config state default-branch)
Without a subcommand, runs get. Use set to override, or clear then get to re-detect.
diff --git a/tests/snapshots/integration__integration_tests__help__help_config_state_logs.snap b/tests/snapshots/integration__integration_tests__help__help_config_state_logs.snap
index 5970e957d..3574a0b99 100644
--- a/tests/snapshots/integration__integration_tests__help__help_config_state_logs.snap
+++ b/tests/snapshots/integration__integration_tests__help__help_config_state_logs.snap
@@ -97,13 +97,13 @@ All logs are stored in .git/wt/logs/ (in the main worktree's git directo
Examples
List all log files:
-  $ wt config state logs get
+  wt config state logs get
Query the command log:
-  $ tail -5 .git/wt/logs/commands.jsonl | jq .
+  tail -5 .git/wt/logs/commands.jsonl | jq .
View a specific hook log:
-  $ cat "$(git rev-parse --git-dir)/wt/logs/feature-project-post-start-build.log"
+  cat "$(git rev-parse --git-dir)/wt/logs/feature-project-post-start-build.log"
Clear all logs:
-  $ wt config state logs clear
+  wt config state logs clear
diff --git a/tests/snapshots/integration__integration_tests__help__help_config_state_marker.snap b/tests/snapshots/integration__integration_tests__help__help_config_state_marker.snap
index 1cc597092..76fb0c6bc 100644
--- a/tests/snapshots/integration__integration_tests__help__help_config_state_marker.snap
+++ b/tests/snapshots/integration__integration_tests__help__help_config_state_marker.snap
@@ -75,6 +75,6 @@ Markers appear at the end of the Status column, after git symbols:
Stored in git config as worktrunk.state.<branch>.marker. Set directly with:
-  $ git config worktrunk.state.feature.marker '{"marker":"🚧","set_at":0}'
+  git config worktrunk.state.feature.marker '{"marker":"🚧","set_at":0}'
Without a subcommand, runs get for the current branch. For --branch, use get --branch=NAME.
diff --git a/tests/snapshots/integration__integration_tests__help__help_hook_approvals.snap b/tests/snapshots/integration__integration_tests__help__help_hook_approvals.snap
index 94e1fcc53..c145d9ac7 100644
--- a/tests/snapshots/integration__integration_tests__help__help_hook_approvals.snap
+++ b/tests/snapshots/integration__integration_tests__help__help_hook_approvals.snap
@@ -60,13 +60,13 @@ Project hooks require approval on first run to prevent untrusted projects from r
Examples
Pre-approve all commands for current project:
-  $ wt hook approvals add
+  wt hook approvals add
Clear approvals for current project:
-  $ wt hook approvals clear
+  wt hook approvals clear
Clear global approvals:
-  $ wt hook approvals clear --global
+  wt hook approvals clear --global
How approvals work
diff --git a/tests/snapshots/integration__integration_tests__help__help_list_long.snap b/tests/snapshots/integration__integration_tests__help__help_list_long.snap
index e66a1b50f..70d2b74e5 100644
--- a/tests/snapshots/integration__integration_tests__help__help_list_long.snap
+++ b/tests/snapshots/integration__integration_tests__help__help_list_long.snap
@@ -85,19 +85,19 @@ The table renders progressively: branch names, paths, and commit hashes appear i
List all worktrees:
-  $ wt list
+  wt list
Include CI status, line diffs, and LLM summaries:
-  $ wt list --full
+  wt list --full
Include branches that don't have worktrees:
-  $ wt list --branches --full
+  wt list --branches --full
Output as JSON for scripting:
-  $ wt list --format=json
+  wt list --format=json
Columns
@@ -187,28 +187,28 @@ These appear across all columns while the table is loading:
Query structured data with --format=json:
  # Current worktree path (for scripts)
-  $ wt list --format=json | jq -r '.[] | select(.is_current) | .path'
+  wt list --format=json | jq -r '.[] | select(.is_current) | .path'
  
  # Branches with uncommitted changes
-  $ wt list --format=json | jq '.[] | select(.working_tree.modified)'
+  wt list --format=json | jq '.[] | select(.working_tree.modified)'
  
  # Worktrees with merge conflicts
-  $ wt list --format=json | jq '.[] | select(.operation_state == "conflicts")'
+  wt list --format=json | jq '.[] | select(.operation_state == "conflicts")'
  
  # Branches ahead of main (needs merging)
-  $ wt list --format=json | jq '.[] | select(.main.ahead > 0) | .branch'
+  wt list --format=json | jq '.[] | select(.main.ahead > 0) | .branch'
  
  # Integrated branches (safe to remove)
-  $ wt list --format=json | jq '.[] | select(.main_state == "integrated" or .main_state == "empty") | .branch'
+  wt list --format=json | jq '.[] | select(.main_state == "integrated" or .main_state == "empty") | .branch'
  
  # Branches without worktrees
-  $ wt list --format=json --branches | jq '.[] | select(.kind == "branch") | .branch'
+  wt list --format=json --branches | jq '.[] | select(.kind == "branch") | .branch'
  
  # Worktrees ahead of remote (needs pushing)
-  $ wt list --format=json | jq '.[] | select(.remote.ahead > 0) | {branch, ahead: .remote.ahead}'
+  wt list --format=json | jq '.[] | select(.remote.ahead > 0) | {branch, ahead: .remote.ahead}'
  
  # Stale CI (local changes not reflected in CI)
-  $ wt list --format=json --full | jq '.[] | select(.ci.stale) | .branch'
+  wt list --format=json --full | jq '.[] | select(.ci.stale) | .branch'
Fields:
diff --git a/tests/snapshots/integration__integration_tests__help__help_list_narrow_80.snap b/tests/snapshots/integration__integration_tests__help__help_list_narrow_80.snap
index 5c15b4bac..18f5ce165 100644
--- a/tests/snapshots/integration__integration_tests__help__help_list_narrow_80.snap
+++ b/tests/snapshots/integration__integration_tests__help__help_list_narrow_80.snap
@@ -93,19 +93,19 @@ and columns fill in as results arrive.
List all worktrees:
-  $ wt list
+  wt list
Include CI status, line diffs, and LLM summaries:
-  $ wt list --full
+  wt list --full
Include branches that don't have worktrees:
-  $ wt list --branches --full
+  wt list --branches --full
Output as JSON for scripting:
-  $ wt list --format=json
+  wt list --format=json
Columns
@@ -209,31 +209,31 @@ These appear across all columns while the table is loading:
Query structured data with --format=json:
  # Current worktree path (for scripts)
-  $ wt list --format=json | jq -r '.[] | select(.is_current) | .path'
+  wt list --format=json | jq -r '.[] | select(.is_current) | .path'
  
  # Branches with uncommitted changes
-  $ wt list --format=json | jq '.[] | select(.working_tree.modified)'
+  wt list --format=json | jq '.[] | select(.working_tree.modified)'
  
  # Worktrees with merge conflicts
-  $ wt list --format=json | jq '.[] | select(.operation_state == "conflicts")'
+  wt list --format=json | jq '.[] | select(.operation_state == "conflicts")'
  
  # Branches ahead of main (needs merging)
-  $ wt list --format=json | jq '.[] | select(.main.ahead > 0) | .branch'
+  wt list --format=json | jq '.[] | select(.main.ahead > 0) | .branch'
  
  # Integrated branches (safe to remove)
-  $ wt list --format=json | jq '.[] | select(.main_state == "integrated" or 
+  wt list --format=json | jq '.[] | select(.main_state == "integrated" or 
  .main_state == "empty") | .branch'
  
  # Branches without worktrees
-  $ wt list --format=json --branches | jq '.[] | select(.kind == "branch") | 
+  wt list --format=json --branches | jq '.[] | select(.kind == "branch") | 
  .branch'
  
  # Worktrees ahead of remote (needs pushing)
-  $ wt list --format=json | jq '.[] | select(.remote.ahead > 0) | {branch, 
-  ahead: .remote.ahead}'
+  wt list --format=json | jq '.[] | select(.remote.ahead > 0) | {branch, ahead: 
+  .remote.ahead}'
  
  # Stale CI (local changes not reflected in CI)
-  $ wt list --format=json --full | jq '.[] | select(.ci.stale) | .branch'
+  wt list --format=json --full | jq '.[] | select(.ci.stale) | .branch'
Fields:
diff --git a/tests/snapshots/integration__integration_tests__help__help_merge_long.snap b/tests/snapshots/integration__integration_tests__help__help_merge_long.snap
index 31efce5db..177d71616 100644
--- a/tests/snapshots/integration__integration_tests__help__help_merge_long.snap
+++ b/tests/snapshots/integration__integration_tests__help__help_merge_long.snap
@@ -94,27 +94,27 @@ Unlike git merge, this merges the current branch into the target branch
Merge to the default branch:
-  $ wt merge
+  wt merge
Merge to a different branch:
-  $ wt merge develop
+  wt merge develop
Keep the worktree after merging:
-  $ wt merge --no-remove
+  wt merge --no-remove
Preserve commit history (no squash):
-  $ wt merge --no-squash
+  wt merge --no-squash
Create a merge commit β€” semi-linear history:
-  $ wt merge --no-ff
+  wt merge --no-ff
Skip committing/squashing (rebase still runs unless --no-rebase):
-  $ wt merge --no-commit
+  wt merge --no-commit
Pipeline
diff --git a/tests/snapshots/integration__integration_tests__help__help_remove_long.snap b/tests/snapshots/integration__integration_tests__help__help_remove_long.snap
index 1fceff4a0..e5b99fd1f 100644
--- a/tests/snapshots/integration__integration_tests__help__help_remove_long.snap
+++ b/tests/snapshots/integration__integration_tests__help__help_remove_long.snap
@@ -81,20 +81,20 @@ Usage: wt remove [OPTIONS] [BRANCHES]...
Remove current worktree:
-  $ wt remove
+  wt remove
Remove specific worktrees / branches:
-  $ wt remove feature-branch
-  $ wt remove old-feature another-branch
+  wt remove feature-branch
+  wt remove old-feature another-branch
Keep the branch:
-  $ wt remove --no-delete-branch feature-branch
+  wt remove --no-delete-branch feature-branch
Force-delete an unmerged branch:
-  $ wt remove -D experimental
+  wt remove -D experimental
Branch cleanup
@@ -122,9 +122,9 @@ Worktrunk has two force flags for different situations:
--force (-f) Worktree Worktree has untracked files
--force-delete (-D) Branch Branch has unmerged commits
-  $ wt remove feature --force # Remove worktree with untracked files
-  $ wt remove feature -D # Delete unmerged branch
-  $ wt remove feature --force -D # Both
+  wt remove feature --force # Remove worktree with untracked files
+  wt remove feature -D # Delete unmerged branch
+  wt remove feature --force -D # Both
Without --force, removal fails if the worktree contains untracked files. Without --force-delete, removal keeps branches with unmerged changes. Use --no-delete-branch to keep the branch regardless of merge status.
diff --git a/tests/snapshots/integration__integration_tests__help__help_step_long.snap b/tests/snapshots/integration__integration_tests__help__help_step_long.snap
index 8e9c9e30b..e31e644ee 100644
--- a/tests/snapshots/integration__integration_tests__help__help_step_long.snap
+++ b/tests/snapshots/integration__integration_tests__help__help_step_long.snap
@@ -69,14 +69,14 @@ Usage: wt step [OPTIONS] <COMMAND>
Commit with LLM-generated message:
-  $ wt step commit
+  wt step commit
Manual merge workflow with review between steps:
-  $ wt step commit
-  $ wt step squash
-  $ wt step rebase
-  $ wt step push
+  wt step commit
+  wt step squash
+  wt step rebase
+  wt step push
Operations
@@ -107,10 +107,10 @@ Custom command templates configured in user config (~/.config/worktrunk/conf
  deploy = "make deploy BRANCH={{ branch }}"
  port = "echo http://localhost:{{ branch | hash_port }}"
-  $ wt step deploy # run the alias
-  $ wt step deploy --dry-run # show expanded command
-  $ wt step deploy --var env=staging # pass extra template variables
-  $ wt step deploy --yes # skip approval prompt
+  wt step deploy # run the alias
+  wt step deploy --dry-run # show expanded command
+  wt step deploy --var env=staging # pass extra template variables
+  wt step deploy --yes # skip approval prompt
When defined in both user and project config, both run β€” user first, then project. Project-config aliases require command approval on first run, same as project hooks. User-config aliases are trusted.
diff --git a/tests/snapshots/integration__integration_tests__help__help_step_promote.snap b/tests/snapshots/integration__integration_tests__help__help_step_promote.snap
index 3c2732a8f..778d0d37a 100644
--- a/tests/snapshots/integration__integration_tests__help__help_step_promote.snap
+++ b/tests/snapshots/integration__integration_tests__help__help_step_promote.snap
@@ -64,7 +64,7 @@ Usage: wt step promote [OPTIONS] [BRANCH]
Example
  # from ~/project (main worktree)
-  $ wt step promote feature
+  wt step promote feature
Before:
diff --git a/tests/snapshots/integration__integration_tests__help__help_switch_long.snap b/tests/snapshots/integration__integration_tests__help__help_switch_long.snap
index 109f86ac8..2e9575d79 100644
--- a/tests/snapshots/integration__integration_tests__help__help_switch_long.snap
+++ b/tests/snapshots/integration__integration_tests__help__help_switch_long.snap
@@ -124,11 +124,11 @@ Worktrees are addressed by branch name; paths are computed from a configurable t
Examples
-  $ wt switch feature-auth # Switch to worktree
-  $ wt switch - # Previous worktree (like cd -)
-  $ wt switch --create new-feature # Create new branch and worktree
-  $ wt switch --create hotfix --base production
-  $ wt switch pr:123 # Switch to PR #123's branch
+  wt switch feature-auth # Switch to worktree
+  wt switch - # Previous worktree (like cd -)
+  wt switch --create new-feature # Create new branch and worktree
+  wt switch --create hotfix --base production
+  wt switch pr:123 # Switch to PR #123's branch
Creating a branch
@@ -144,10 +144,10 @@ If the branch already has a worktree, wt switch changes directories to i
4. Runs pre-start hooks, blocking until complete
5. Spawns post-start and post-switch hooks in the background
-  $ wt switch feature # Existing branch β†’ creates worktree
-  $ wt switch --create feature # New branch and worktree
-  $ wt switch --create fix --base release # New branch from release
-  $ wt switch --create temp --no-hooks # Skip hooks
+  wt switch feature # Existing branch β†’ creates worktree
+  wt switch --create feature # New branch and worktree
+  wt switch --create fix --base release # New branch from release
+  wt switch --create temp --no-hooks # Skip hooks
Shortcuts
@@ -159,11 +159,11 @@ If the branch already has a worktree, wt switch changes directories to i
pr:{N} GitHub PR #N's branch
mr:{N} GitLab MR !N's branch
-  $ wt switch - # Back to previous
-  $ wt switch ^ # Default branch worktree
-  $ wt switch --create fix --base=@ # Branch from current HEAD
-  $ wt switch pr:123 # PR #123's branch
-  $ wt switch mr:101 # MR !101's branch
+  wt switch - # Back to previous
+  wt switch ^ # Default branch worktree
+  wt switch --create fix --base=@ # Branch from current HEAD
+  wt switch pr:123 # PR #123's branch
+  wt switch mr:101 # MR !101's branch
Interactive picker
@@ -201,8 +201,8 @@ Available on Unix only (macOS, Linux). On Windows, use wt list or wt
The pr:<number> and mr:<number> shortcuts resolve a GitHub PR or GitLab MR to its branch. For same-repo PRs/MRs, worktrunk switches to the branch directly. For fork PRs/MRs, it fetches the ref (refs/pull/N/head or refs/merge-requests/N/head) and configures pushRemote to the fork URL.
-  $ wt switch pr:101 # GitHub PR #101
-  $ wt switch mr:101 # GitLab MR !101
+  wt switch pr:101 # GitHub PR #101
+  wt switch mr:101 # GitLab MR !101
Requires gh (GitHub) or glab (GitLab) CLI to be installed and authenticated. The --create flag cannot be used with pr:/mr: syntax since the branch already exists.