Skip to content

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

feat: Write commented example config to disk

Maximilian Roos0516788184e6
diff --git a/dev/config.example.toml b/dev/config.example.toml
index 4d78a9233..437337ce3 100644
--- a/dev/config.example.toml
+++ b/dev/config.example.toml
@@ -28,8 +28,8 @@ worktree-path = "../{{ main_worktree }}.{{ branch }}"
[commit-generation]
# Example: Simon Willison's llm CLI (https://github.com/simonw/llm)
# Install: pip install llm llm-anthropic
-# command = "llm"
-# args = ["-m", "claude-haiku-4.5"]
+command = "llm"
+args = ["-m", "claude-haiku-4.5"]
# Alternative: AIChat - Rust-based, supports 20+ providers
# Install from: https://github.com/sigoden/aichat
@@ -151,26 +151,26 @@ worktree-path = "../{{ main_worktree }}.{{ branch }}"
# List Command Defaults
# Configure default behavior for `wt list`
-# [list]
-# full = false # Show CI, conflicts, diffs by default
-# branches = false # Include branches without worktrees by default
-# remotes = false # Include remote branches by default
+[list]
+full = false # Show CI, conflicts, diffs by default
+branches = false # Include branches without worktrees by default
+remotes = false # Include remote branches by default
# Commit Defaults (shared by `wt beta commit`, `wt beta squash`, and `wt merge`)
-# [commit]
-# stage = "all" # What to stage: "all", "tracked", or "none"
+[commit]
+stage = "all" # What to stage: "all", "tracked", or "none"
# Merge Command Defaults
# Note: `stage` defaults from [commit] section above
-# [merge]
-# squash = true # Squash commits when merging
-# commit = true # Create commit after merge
-# remove = true # Remove worktree after merge
-# verify = true # Run project hooks
+[merge]
+squash = true # Squash commits when merging
+commit = true # Create commit after merge
+remove = true # Remove worktree after merge
+verify = true # Run project hooks
# Approved Commands
# Commands approved for automatic execution after switching worktrees
# Auto-populated when you use: wt switch --execute "command" --force
-# [[approved-commands]]
-# project = "github.com/user/repo"
-# command = "npm install"
+[[approved-commands]]
+project = "github.com/user/repo"
+command = "npm install"
diff --git a/src/commands/config.rs b/src/commands/config.rs
index b72f10827..674ed1f22 100644
--- a/src/commands/config.rs
+++ b/src/commands/config.rs
@@ -8,9 +8,32 @@ use worktrunk::styling::{
format_toml, print, println,
};
-/// Example configuration file content
+/// Example configuration file content (displayed in help with values uncommented)
const CONFIG_EXAMPLE: &str = include_str!("../../dev/config.example.toml");
+/// Comment out all non-comment, non-empty lines for writing to disk
+fn comment_out_config(content: &str) -> String {
+ let has_trailing_newline = content.ends_with('\n');
+ let result = content
+ .lines()
+ .map(|line| {
+ // Comment out non-empty lines that aren't already comments
+ if !line.is_empty() && !line.starts_with('#') {
+ format!("# {}", line)
+ } else {
+ line.to_string()
+ }
+ })
+ .collect::<Vec<_>>()
+ .join("\n");
+
+ if has_trailing_newline {
+ format!("{}\n", result)
+ } else {
+ result
+ }
+}
+
/// Handle the config create command
pub fn handle_config_create() -> anyhow::Result<()> {
let config_path = get_global_config_path()
@@ -34,8 +57,9 @@ pub fn handle_config_create() -> anyhow::Result<()> {
.map_err(|e| anyhow::anyhow!("Failed to create config directory: {}", e))?;
}
- // Write the example config
- std::fs::write(&config_path, CONFIG_EXAMPLE).context("Failed to write config file")?;
+ // Write the example config with all values commented out
+ let commented_config = comment_out_config(CONFIG_EXAMPLE);
+ std::fs::write(&config_path, commented_config).context("Failed to write config file")?;
// Success message
let green_bold = GREEN.bold();
diff --git a/tests/snapshots/integration__integration_tests__help__help_config_create.snap b/tests/snapshots/integration__integration_tests__help__help_config_create.snap
index ecd14e2f8..33cc61e79 100644
--- a/tests/snapshots/integration__integration_tests__help__help_config_create.snap
+++ b/tests/snapshots/integration__integration_tests__help__help_config_create.snap
@@ -64,8 +64,8 @@ Creates ~/.config/worktrunk/config.toml with the following content:
[commit-generation]
# Example: Simon Willison's llm CLI (https://github.com/simonw/llm)
# Install: pip install llm llm-anthropic
- # command = "llm"
- # args = ["-m", "claude-haiku-4.5"]
+ command = "llm"
+ args = ["-m", "claude-haiku-4.5"]

# Alternative: AIChat - Rust-based, supports 20+ providers
# Install from: https://github.com/sigoden/aichat
@@ -187,28 +187,28 @@ Creates ~/.config/worktrunk/config.toml with the following content:

# List Command Defaults
# Configure default behavior for `wt list`
- # [list]
- # full = false # Show CI, conflicts, diffs by default
- # branches = false # Include branches without worktrees by default
- # remotes = false # Include remote branches by default
+ [list]
+ full = false # Show CI, conflicts, diffs by default
+ branches = false # Include branches without worktrees by default
+ remotes = false # Include remote branches by default

# Commit Defaults (shared by `wt beta commit`, `wt beta squash`, and `wt merge`)
- # [commit]
- # stage = "all" # What to stage: "all", "tracked", or "none"
+ [commit]
+ stage = "all" # What to stage: "all", "tracked", or "none"

# Merge Command Defaults
# Note: `stage` defaults from [commit] section above
- # [merge]
- # squash = true # Squash commits when merging
- # commit = true # Create commit after merge
- # remove = true # Remove worktree after merge
- # verify = true # Run project hooks
+ [merge]
+ squash = true # Squash commits when merging
+ commit = true # Create commit after merge
+ remove = true # Remove worktree after merge
+ verify = true # Run project hooks

# Approved Commands
# Commands approved for automatic execution after switching worktrees
# Auto-populated when you use: wt switch --execute "command" --force
- # [[approved-commands]]
- # project = "github.com/user/repo"
- # command = "npm install"
+ [[approved-commands]]
+ project = "github.com/user/repo"
+ command = "npm install"
----- stderr -----