Skip to content

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

fix(pager): set COLUMNS env var for pager width detection (#930)

Maximilian Roos9616892495c2
diff --git a/.claude-plugin/skills/worktrunk/reference/switch.md b/.claude-plugin/skills/worktrunk/reference/switch.md
index 64f96cf76..99b0cde59 100644
--- a/.claude-plugin/skills/worktrunk/reference/switch.md
+++ b/.claude-plugin/skills/worktrunk/reference/switch.md
@@ -85,7 +85,7 @@ When called without arguments, `wt switch` opens an interactive picker to browse
```toml
[select]
-pager = "delta --paging=never"
+pager = "delta --paging=never --width=$COLUMNS"
```
Available on Unix only (macOS, Linux). On Windows, use `wt list` or `wt switch <branch>` directly.
diff --git a/docs/content/switch.md b/docs/content/switch.md
index aeda1fd8b..b51b9c6f2 100644
--- a/docs/content/switch.md
+++ b/docs/content/switch.md
@@ -107,7 +107,7 @@ When called without arguments, `wt switch` opens an interactive picker to browse
```toml
[select]
-pager = "delta --paging=never"
+pager = "delta --paging=never --width=$COLUMNS"
```
Available on Unix only (macOS, Linux). On Windows, use `wt list` or `wt switch <branch>` directly.
diff --git a/src/cli/mod.rs b/src/cli/mod.rs
index 1c506589f..f3d94dafa 100644
--- a/src/cli/mod.rs
+++ b/src/cli/mod.rs
@@ -336,7 +336,7 @@ When called without arguments, `wt switch` opens an interactive picker to browse
```toml
[select]
-pager = "delta --paging=never"
+pager = "delta --paging=never --width=$COLUMNS"
```
Available on Unix only (macOS, Linux). On Windows, use `wt list` or `wt switch <branch>` directly.
diff --git a/src/commands/select/items.rs b/src/commands/select/items.rs
index f431e2a10..b116dbd73 100644
--- a/src/commands/select/items.rs
+++ b/src/commands/select/items.rs
@@ -137,7 +137,7 @@ impl WorktreeSkimItem {
// Try streaming through pager first (git diff | pager), fall back to plain diff
let diff = get_diff_pager()
- .and_then(|pager| run_git_diff_with_pager(&diff_args, pager))
+ .and_then(|pager| run_git_diff_with_pager(&diff_args, pager, width))
.or_else(|| repo.run_command(&diff_args).ok());
if let Some(diff) = diff {
diff --git a/src/commands/select/pager.rs b/src/commands/select/pager.rs
index ff8f21cb6..dcb41ece2 100644
--- a/src/commands/select/pager.rs
+++ b/src/commands/select/pager.rs
@@ -91,10 +91,17 @@ pub(super) fn has_explicit_pager_config() -> bool {
/// Runs `git <args> | pager` as a single shell command, avoiding intermediate
/// buffering. Returns None if pipeline fails or times out (caller should fall back to raw diff).
///
+/// Sets `COLUMNS` environment variable to the preview width, allowing pagers to detect
+/// the correct width. For pagers like delta with side-by-side mode, users can reference
+/// this in their config: `[select] pager = "delta --width=$COLUMNS"`.
+///
/// When `[select] pager` is not configured, automatically appends `--paging=never` for
-/// delta/bat/batcat pagers to prevent hangs. To override this behavior, set an explicit
-/// pager command in config: `[select] pager = "delta"` (or with custom flags).
-pub(super) fn run_git_diff_with_pager(git_args: &[&str], pager_cmd: &str) -> Option<String> {
+/// delta/bat/batcat pagers to prevent hangs.
+pub(super) fn run_git_diff_with_pager(
+ git_args: &[&str],
+ pager_cmd: &str,
+ width: usize,
+) -> Option<String> {
// Note: pager_cmd is expected to be valid shell code (like git's core.pager).
// Users with paths containing special chars must quote them in their config.
@@ -117,12 +124,14 @@ pub(super) fn run_git_diff_with_pager(git_args: &[&str], pager_cmd: &str) -> Opt
log::debug!("Running pager pipeline: {}", pipeline);
- // Spawn pipeline
+ // Spawn pipeline with COLUMNS set to preview width
+ // Pagers can use this directly (e.g., `delta --width=$COLUMNS`)
let mut child = match Command::new("sh")
.arg("-c")
.arg(&pipeline)
.stdout(Stdio::piped())
.stderr(Stdio::null())
+ .env("COLUMNS", width.to_string())
// Prevent subprocesses from writing to the directive file
.env_remove(worktrunk::shell_exec::DIRECTIVE_FILE_ENV_VAR)
.spawn()
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 a643b1033..ff9cdc1e5 100644
--- a/tests/snapshots/integration__integration_tests__help__help_switch_long.snap
+++ b/tests/snapshots/integration__integration_tests__help__help_switch_long.snap
@@ -173,7 +173,7 @@ When called without arguments, wt switch opens an interactive picker to
Pager configuration: The preview panel pipes diff output through git's pager. Override in user config:
[select]
- pager = "delta --paging=never"
+ pager = "delta --paging=never --width=$COLUMNS"
Available on Unix only (macOS, Linux). On Windows, use wt list or wt switch <branch> directly.