Skip to content

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

Remove external pager support in select preview

Maximilian Roos0503ff76d793
diff --git a/src/commands/select.rs b/src/commands/select.rs
index 80e98d800..71315ab76 100644
--- a/src/commands/select.rs
+++ b/src/commands/select.rs
@@ -132,8 +132,13 @@ impl WorktreeSkimItem {
output.push_str(&stat);
output.push_str("\n\n");
- // Show full diff with pager (spawned via setsid to prevent TTY access)
- if let Ok(diff) = repo.run_diff_with_pager(args) {
+ // TODO: Re-enable user pager (delta, diff-so-fancy, etc.) for diff preview
+ // Currently disabled because pagers can interfere with skim's TUI rendering.
+ // When re-implementing, test with: GIT_PAGER=delta cargo run -- beta select
+ // Consider: config option to disable pagers specifically for select preview
+ let mut diff_args = args.to_vec();
+ diff_args.push("--color=always");
+ if let Ok(diff) = repo.run_command(&diff_args) {
output.push_str(&diff);
}
} else {
diff --git a/src/git/repository/mod.rs b/src/git/repository/mod.rs
index 0cb024d15..326b3714d 100644
--- a/src/git/repository/mod.rs
+++ b/src/git/repository/mod.rs
@@ -1,6 +1,5 @@
-use std::io::Write;
use std::path::PathBuf;
-use std::process::{Command, Stdio};
+use std::process::Command;
use std::sync::OnceLock;
use anyhow::{Context, bail};
@@ -1220,135 +1219,6 @@ impl Repository {
}
Ok(success)
}
-
- /// Run git diff through a renderer (pager) if configured, otherwise return colored diff output.
- ///
- /// The pager is spawned in a detached session (via setsid on Unix) to prevent it from
- /// accessing /dev/tty, which would cause hangs when called from within TUI contexts like skim.
- pub fn run_diff_with_pager(&self, args: &[&str]) -> anyhow::Result<String> {
- let mut git_args = args.to_vec();
- git_args.push("--color=always");
- let git_output = self.run_command(&git_args)?;
-
- let result = match pager_config().as_ref() {
- Some(pager_cmd) => invoke_renderer(pager_cmd, &git_output).unwrap_or(git_output),
- None => {
- log::debug!("Using git output directly");
- git_output
- }
- };
-
- Ok(result)
- }
-}
-
-fn pager_config() -> &'static Option<String> {
- static PAGER_CONFIG: OnceLock<Option<String>> = OnceLock::new();
- PAGER_CONFIG.get_or_init(detect_pager)
-}
-
-fn detect_pager() -> Option<String> {
- let repo = Repository::current();
-
- let validate = |s: &str| -> Option<String> {
- let trimmed = s.trim();
- (!trimmed.is_empty() && trimmed != "cat").then(|| trimmed.to_string())
- };
-
- std::env::var("GIT_PAGER")
- .ok()
- .and_then(|s| validate(&s))
- .or_else(|| {
- repo.run_command(&["config", "--get", "pager.diff"])
- .ok()
- .and_then(|s| validate(&s))
- })
- .or_else(|| {
- repo.run_command(&["config", "--get", "core.pager"])
- .ok()
- .and_then(|s| validate(&s))
- })
- .or_else(|| std::env::var("PAGER").ok().and_then(|s| validate(&s)))
-}
-
-#[cfg(unix)]
-#[allow(unsafe_code)] // Required for pre_exec + setsid to detach from controlling terminal
-fn invoke_renderer(pager_cmd: &str, git_output: &str) -> Option<String> {
- use std::os::unix::process::CommandExt;
-
- log::debug!("Invoking renderer: {}", pager_cmd);
-
- let mut cmd = Command::new("sh");
- cmd.arg("-c")
- .arg(pager_cmd)
- .stdin(Stdio::piped())
- .stdout(Stdio::piped())
- .stderr(Stdio::null())
- .env("PAGER", "cat")
- .env("DELTA_PAGER", "cat")
- .env("BAT_PAGER", "")
- .env("DELTA_NAVIGATE", "0"); // Disable interactive navigate mode (requires TTY)
-
- // Detach from controlling terminal to prevent pager from accessing /dev/tty
- // This is critical for TUI contexts (like skim preview) where TTY access would hang
- //
- // SAFETY: pre_exec is safe here because:
- // - setsid() is async-signal-safe (can be called between fork and exec)
- // - We don't access any memory from the parent process
- // - We don't perform any allocations or other unsafe operations
- // - setsid() cannot fail in this context (fresh fork, not a process group leader)
- unsafe {
- cmd.pre_exec(|| {
- // setsid() cannot fail after fork() - we're not a process group leader yet
- let _ = nix::unistd::setsid();
- Ok(())
- });
- }
-
- let child = cmd.spawn().ok()?;
- handle_pager_io(child, git_output)
-}
-
-#[cfg(windows)]
-fn invoke_renderer(pager_cmd: &str, git_output: &str) -> Option<String> {
- use std::os::windows::process::CommandExt;
-
- log::debug!("Invoking renderer: {}", pager_cmd);
-
- const CREATE_NEW_PROCESS_GROUP: u32 = 0x00000200;
- const DETACHED_PROCESS: u32 = 0x00000008;
-
- let mut cmd = Command::new("cmd");
- cmd.arg("/C")
- .arg(pager_cmd)
- .stdin(Stdio::piped())
- .stdout(Stdio::piped())
- .stderr(Stdio::null())
- .env("PAGER", "cat")
- .env("DELTA_PAGER", "cat")
- .env("BAT_PAGER", "")
- .env("DELTA_NAVIGATE", "0") // Disable interactive navigate mode (requires TTY)
- .creation_flags(CREATE_NEW_PROCESS_GROUP | DETACHED_PROCESS);
-
- let child = cmd.spawn().ok()?;
- handle_pager_io(child, git_output)
-}
-
-/// Common I/O handling for pager child processes
-fn handle_pager_io(mut child: std::process::Child, git_output: &str) -> Option<String> {
- if let Some(mut stdin) = child.stdin.take() {
- let _ = stdin.write_all(git_output.as_bytes());
- drop(stdin);
- }
-
- let output = child.wait_with_output().ok()?;
- if output.status.success() {
- log::debug!("Renderer succeeded, output len={}", output.stdout.len());
- String::from_utf8(output.stdout).ok()
- } else {
- log::debug!("Renderer failed with status={:?}", output.status);
- None
- }
}
#[cfg(test)]