Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
Refactor: Separate stdout and stderr in shell integrations
Maximilian Roos0e38a913767f
diff --git a/templates/bash.sh b/templates/bash.shindex 5ecffd204..ced5b9683 100644--- a/templates/bash.sh+++ b/templates/bash.sh@@ -13,8 +13,8 @@ if command -v wt >/dev/null 2>&1; thenlocal exit_code_fileexit_code_file=$(mktemp) || { echo "Failed to create temp file" >&2; return 1; }- # Parse output directly from wt (command substitution strips NUL bytes!)- # Use process substitution to preserve NUL bytes+ # Parse stdout for directives (NUL-delimited)+ # Let stderr pass through to terminal (preserves TTY for color detection)# Write exit code to temp file since it can't be captured from process substitution# The || [[ -n "$chunk" ]] handles non-NUL-terminated output (e.g., error messages)while IFS= read -r -d '' chunk || [[ -n "$chunk" ]]; do@@ -29,7 +29,7 @@ if command -v wt >/dev/null 2>&1; then# Regular output - print it (preserving newlines)printf '%s' "$chunk"fi- done < <(command "$_WORKTRUNK_CMD" "$@" 2>&1; echo "$?" > "$exit_code_file")+ done < <(command "$_WORKTRUNK_CMD" "$@"; echo "$?" > "$exit_code_file")# Read exit code from temp fileexit_code=$(cat "$exit_code_file" 2>/dev/null || echo 0)diff --git a/templates/elvish.elv b/templates/elvish.elvindex 5bd4cf79a..dc5479580 100644--- a/templates/elvish.elv+++ b/templates/elvish.elv@@ -16,10 +16,11 @@ if (has-external wt) {var output = ""var exec-cmd = ""- # Capture output and handle potential non-zero exit+ # Capture stdout for directives, let stderr pass through to terminal+ # This preserves TTY for color detection# TODO: Capture actual exit code from wt command, not just success/failuretry {- set output = (e:$_WORKTRUNK_CMD $@args 2>&1 | slurp)+ set output = (e:$_WORKTRUNK_CMD $@args | slurp)} catch e {set exit-code = 1set output = $e[reason][content]diff --git a/templates/fish.fish b/templates/fish.fishindex 47808d58d..f2ee40843 100644--- a/templates/fish.fish+++ b/templates/fish.fish@@ -65,7 +65,7 @@ if type -q {{ cmd_prefix }}endprintf '%s' $chunkend- end < (begin; command $_WORKTRUNK_CMD $argv 2>&1; echo $status > $exit_code_file; end | psub)+ end < (begin; command $_WORKTRUNK_CMD $argv; echo $status > $exit_code_file; end | psub)if test $debug_mode -eq 1echo "[DEBUG] Finished reading, total chunks: $chunk_count" >&2diff --git a/templates/powershell.ps1 b/templates/powershell.ps1index 3101818c0..e9e09c228 100644--- a/templates/powershell.ps1+++ b/templates/powershell.ps1@@ -14,8 +14,9 @@ if (Get-Command wt -ErrorAction SilentlyContinue) {[string[]]$Arguments)- # Capture output and exit code- $output = & $script:_WORKTRUNK_CMD @Arguments 2>&1 | Out-String+ # Capture stdout for directives, let stderr pass through to terminal+ # This preserves TTY for color detection+ $output = & $script:_WORKTRUNK_CMD @Arguments | Out-String$exitCode = $LASTEXITCODE$execCmd = ""diff --git a/tests/snapshots/integration__integration_tests__init__init_bash.snap b/tests/snapshots/integration__integration_tests__init__init_bash.snapindex 81bc3b1c5..c464c1ada 100644--- a/tests/snapshots/integration__integration_tests__init__init_bash.snap+++ b/tests/snapshots/integration__integration_tests__init__init_bash.snap@@ -34,8 +34,8 @@ if command -v wt >/dev/null 2>&1; thenlocal exit_code_fileexit_code_file=$(mktemp) || { echo "Failed to create temp file" >&2; return 1; }- # Parse output directly from wt (command substitution strips NUL bytes!)- # Use process substitution to preserve NUL bytes+ # Parse stdout for directives (NUL-delimited)+ # Let stderr pass through to terminal (preserves TTY for color detection)# Write exit code to temp file since it can't be captured from process substitution# The || [[ -n "$chunk" ]] handles non-NUL-terminated output (e.g., error messages)while IFS= read -r -d '' chunk || [[ -n "$chunk" ]]; do@@ -50,7 +50,7 @@ if command -v wt >/dev/null 2>&1; then# Regular output - print it (preserving newlines)printf '%s' "$chunk"fi- done < <(command "$_WORKTRUNK_CMD" "$@" 2>&1; echo "$?" > "$exit_code_file")+ done < <(command "$_WORKTRUNK_CMD" "$@"; echo "$?" > "$exit_code_file")# Read exit code from temp fileexit_code=$(cat "$exit_code_file" 2>/dev/null || echo 0)diff --git a/tests/snapshots/integration__integration_tests__init__init_bash_custom_prefix.snap b/tests/snapshots/integration__integration_tests__init__init_bash_custom_prefix.snapindex 057960a3b..6f541f1a1 100644--- a/tests/snapshots/integration__integration_tests__init__init_bash_custom_prefix.snap+++ b/tests/snapshots/integration__integration_tests__init__init_bash_custom_prefix.snap@@ -36,8 +36,8 @@ if command -v wt >/dev/null 2>&1; thenlocal exit_code_fileexit_code_file=$(mktemp) || { echo "Failed to create temp file" >&2; return 1; }- # Parse output directly from wt (command substitution strips NUL bytes!)- # Use process substitution to preserve NUL bytes+ # Parse stdout for directives (NUL-delimited)+ # Let stderr pass through to terminal (preserves TTY for color detection)# Write exit code to temp file since it can't be captured from process substitution# The || [[ -n "$chunk" ]] handles non-NUL-terminated output (e.g., error messages)while IFS= read -r -d '' chunk || [[ -n "$chunk" ]]; do@@ -52,7 +52,7 @@ if command -v wt >/dev/null 2>&1; then# Regular output - print it (preserving newlines)printf '%s' "$chunk"fi- done < <(command "$_WORKTRUNK_CMD" "$@" 2>&1; echo "$?" > "$exit_code_file")+ done < <(command "$_WORKTRUNK_CMD" "$@"; echo "$?" > "$exit_code_file")# Read exit code from temp fileexit_code=$(cat "$exit_code_file" 2>/dev/null || echo 0)diff --git a/tests/snapshots/integration__integration_tests__init__init_fish.snap b/tests/snapshots/integration__integration_tests__init__init_fish.snapindex 6140870c4..ddeb266a8 100644--- a/tests/snapshots/integration__integration_tests__init__init_fish.snap+++ b/tests/snapshots/integration__integration_tests__init__init_fish.snap@@ -86,7 +86,7 @@ if type -q wtendprintf '%s' $chunkend- end < (begin; command $_WORKTRUNK_CMD $argv 2>&1; echo $status > $exit_code_file; end | psub)+ end < (begin; command $_WORKTRUNK_CMD $argv; echo $status > $exit_code_file; end | psub)if test $debug_mode -eq 1echo "[DEBUG] Finished reading, total chunks: $chunk_count" >&2diff --git a/tests/snapshots/integration__integration_tests__init__init_zsh.snap b/tests/snapshots/integration__integration_tests__init__init_zsh.snapindex c7c7c647f..5735d1fa7 100644--- a/tests/snapshots/integration__integration_tests__init__init_zsh.snap+++ b/tests/snapshots/integration__integration_tests__init__init_zsh.snap@@ -34,8 +34,8 @@ if command -v wt >/dev/null 2>&1; thenlocal exit_code_fileexit_code_file=$(mktemp) || { echo "Failed to create temp file" >&2; return 1; }- # Parse output directly from wt (command substitution strips NUL bytes!)- # Use process substitution to preserve NUL bytes+ # Parse stdout for directives (NUL-delimited)+ # Let stderr pass through to terminal (preserves TTY for color detection)# Write exit code to temp file since it can't be captured from process substitution# The || [[ -n "$chunk" ]] handles non-NUL-terminated output (e.g., error messages)while IFS= read -r -d '' chunk || [[ -n "$chunk" ]]; do@@ -50,7 +50,7 @@ if command -v wt >/dev/null 2>&1; then# Regular output - print it (preserving newlines)printf '%s' "$chunk"fi- done < <(command "$_WORKTRUNK_CMD" "$@" 2>&1; echo "$?" > "$exit_code_file")+ done < <(command "$_WORKTRUNK_CMD" "$@"; echo "$?" > "$exit_code_file")# Read exit code from temp fileexit_code=$(cat "$exit_code_file" 2>/dev/null || echo 0)