Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
Clarify shell integration purpose in docs
Maximilian Roosa458da872639
diff --git a/README.md b/README.mdindex 0d17e45e2..5c7557c4b 100644--- a/README.md+++ b/README.md@@ -93,9 +93,11 @@ git branch -d feat</pre></td>```bash$ brew install max-sixty/worktrunk/wt-$ wt config shell install # allows commands to change directories+$ wt config shell install```+Shell integration allows commands to change directories.+**Cargo:**```bashdiff --git a/docs/content/worktrunk.md b/docs/content/worktrunk.mdindex ffb114b90..2e7887a90 100644--- a/docs/content/worktrunk.md+++ b/docs/content/worktrunk.md@@ -83,9 +83,11 @@ git branch -d feat{% end %}</td>```bash$ brew install max-sixty/worktrunk/wt-$ wt config shell install # allows commands to change directories+$ wt config shell install```+Shell integration allows commands to change directories.+**Cargo:**```bashdiff --git a/src/commands/list/ci_status.rs b/src/commands/list/ci_status.rsindex 63c0edfa2..4f0a082f3 100644--- a/src/commands/list/ci_status.rs+++ b/src/commands/list/ci_status.rs@@ -803,7 +803,7 @@ fn get_gitlab_project_id(repo_root: &str) -> Option<u64> {cmd.args(["repo", "view", "--output", "json"]);cmd.current_dir(repo_root);// Disable color/pager to avoid ANSI noise in JSON output- disable_color_output(&mut cmd);+ configure_non_interactive(&mut cmd);cmd.env("PAGER", "cat");let output = run(&mut cmd, None).ok()?;@@ -823,30 +823,45 @@ fn get_gitlab_project_id(repo_root: &str) -> Option<u64> {.map(|info| info.id)}-/// Configure command to disable color output-fn disable_color_output(cmd: &mut Command) {+/// Configure command for non-interactive batch execution.+///+/// This prevents tools like `gh` and `glab` from:+/// - Prompting for user input (stdin set to /dev/null)+/// - Using TTY-specific output formatting+/// - Opening browsers for authentication+fn configure_non_interactive(cmd: &mut Command) {+ use std::process::Stdio;+ cmd.stdin(Stdio::null());cmd.env_remove("CLICOLOR_FORCE");cmd.env_remove("GH_FORCE_TTY");cmd.env("NO_COLOR", "1");cmd.env("CLICOLOR", "0");+ cmd.env("GH_PROMPT_DISABLED", "1");}/// Check if a CLI tool is available////// On Windows, this uses `cmd.exe /c` to properly resolve batch files (.cmd/.bat)/// that may be in PATH, since Rust's Command::new doesn't search PATHEXT.+///+/// Uses `Stdio::null()` for stdin to prevent tools like `gh` from prompting+/// for user input when they detect a TTY.fn tool_available(tool: &str, args: &[&str]) -> bool {+ use std::process::Stdio;+#[cfg(windows)]let mut cmd = {let cmd_str = format!("{} {}", tool, args.join(" "));let mut c = Command::new("cmd");c.args(["/c", &cmd_str]);+ c.stdin(Stdio::null());c};#[cfg(not(windows))]let mut cmd = {let mut c = Command::new(tool);c.args(args);+ c.stdin(Stdio::null());c};@@ -1306,9 +1321,11 @@ impl PrStatus {/// - Organization repos (PRs from org branches)/// - Multiple users with same branch namefn detect_github(branch: &str, local_head: &str, repo_root: &str) -> Option<Self> {+ use std::process::Stdio;// Check if gh is available and authenticatedlet mut auth_cmd = Command::new("gh");auth_cmd.args(["auth", "status"]);+ auth_cmd.stdin(Stdio::null());match run(&mut auth_cmd, None) {Err(e) => {log::debug!("gh not available for {}: {}", branch, e);@@ -1347,7 +1364,7 @@ impl PrStatus {"headRefOid,mergeStateStatus,statusCheckRollup,url,headRepositoryOwner",]);- disable_color_output(&mut cmd);+ configure_non_interactive(&mut cmd);cmd.current_dir(repo_root);let output = match run(&mut cmd, None) {@@ -1550,7 +1567,7 @@ impl PrStatus {"status,conclusion,headSha",]);- disable_color_output(&mut cmd);+ configure_non_interactive(&mut cmd);cmd.current_dir(repo_root);let output = match run(&mut cmd, None) {@@ -1596,9 +1613,11 @@ impl PrStatus {}// Get most recent pipeline for the branch using JSON output+ use std::process::Stdio;let mut cmd = Command::new("glab");cmd.args(["ci", "list", "--per-page", "1", "--output", "json"])- .env("BRANCH", branch); // glab ci list uses BRANCH env var+ .env("BRANCH", branch) // glab ci list uses BRANCH env var+ .stdin(Stdio::null());let output = match run(&mut cmd, None) {Ok(output) => output,diff --git a/tests/common/mod.rs b/tests/common/mod.rsindex 65adb5808..4c01b9b6e 100644--- a/tests/common/mod.rs+++ b/tests/common/mod.rs@@ -839,6 +839,8 @@ impl TestRepo {cmd.env("LC_ALL", "C");cmd.env("LANG", "C");cmd.env("SOURCE_DATE_EPOCH", TEST_EPOCH.to_string());+ // Prevent git from prompting for credentials when running under a TTY+ cmd.env("GIT_TERMINAL_PROMPT", "0");}/// Get standard test environment variables as a vector@@ -863,6 +865,8 @@ impl TestRepo {"GIT_COMMITTER_DATE".to_string(),"2025-01-01T00:00:00Z".to_string(),),+ // Prevent git from prompting for credentials when running under a TTY+ ("GIT_TERMINAL_PROMPT".to_string(), "0".to_string()),("LC_ALL".to_string(), "C".to_string()),("LANG".to_string(), "C".to_string()),("SOURCE_DATE_EPOCH".to_string(), TEST_EPOCH.to_string()),diff --git a/tests/common/shell.rs b/tests/common/shell.rsindex ed2c31240..0985d3e2e 100644--- a/tests/common/shell.rs+++ b/tests/common/shell.rs@@ -1,50 +1,44 @@use super::{TestRepo, wt_command};use insta_cmd::get_cargo_bin;-use std::{collections::HashSet, env, path::PathBuf, process::Command, sync::LazyLock};+use std::{+ collections::HashSet,+ env,+ path::PathBuf,+ process::{Command, Stdio},+ sync::LazyLock,+};++/// Check if a shell binary is available (non-interactive)+fn check_shell_available(binary: &str, arg: &str) -> bool {+ Command::new(binary)+ .arg(arg)+ .stdin(Stdio::null())+ .stdout(Stdio::null())+ .stderr(Stdio::null())+ .status()+ .map(|s| s.success())+ .unwrap_or(false)+}/// Set of shells available on this system (cached at first access)static AVAILABLE_SHELLS: LazyLock<HashSet<&'static str>> = LazyLock::new(|| {let mut shells = HashSet::new();- // Check bash availability- if Command::new("bash")- .arg("--version")- .output()- .map(|o| o.status.success())- .unwrap_or(false)- {+ if check_shell_available("bash", "--version") {shells.insert("bash");}- // Check zsh availability (typically not on Windows)- if Command::new("zsh")- .arg("--version")- .output()- .map(|o| o.status.success())- .unwrap_or(false)- {+ if check_shell_available("zsh", "--version") {shells.insert("zsh");}- // Check fish availability (typically not on Windows)- if Command::new("fish")- .arg("--version")- .output()- .map(|o| o.status.success())- .unwrap_or(false)- {+ if check_shell_available("fish", "--version") {shells.insert("fish");}- // Check PowerShell Core availability (pwsh, cross-platform)- if Command::new("pwsh")- .arg("-Version")- .output()- .map(|o| o.status.success())- .unwrap_or(false)- {+ if check_shell_available("pwsh", "-Version") {shells.insert("pwsh");- shells.insert("powershell"); // Alias+ shells.insert("powershell");}shells