Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
Streamline `--source` execution in shell wrappers
Maximilian Roos42de37e9b4ff
diff --git a/templates/bash.sh b/templates/bash.shindex 7b553d930..3f2c31597 100644--- a/templates/bash.sh+++ b/templates/bash.sh@@ -16,7 +16,6 @@ if command -v {{ cmd_prefix }} >/dev/null 2>&1 || [[ -n "${WORKTRUNK_BIN:-}" ]];local use_source=falselocal args=()- local saved_bin="$WORKTRUNK_BIN"# Check for --source flag and strip itfor arg in "$@"; do@@ -27,27 +26,26 @@ if command -v {{ cmd_prefix }} >/dev/null 2>&1 || [[ -n "${WORKTRUNK_BIN:-}" ]];fidone- # If --source was specified, build and use local debug binary- if [[ "$use_source" == true ]]; then- if ! cargo build --quiet; then- return 1- fi- export WORKTRUNK_BIN="./target/debug/{{ cmd_prefix }}"- fi-# Force colors if stderr is a TTY (directive mode outputs to stderr)# Respects NO_COLOR and explicit CLICOLOR_FORCEif [[ -z "${NO_COLOR:-}" && -z "${CLICOLOR_FORCE:-}" ]]; thenif [[ -t 2 ]]; then export CLICOLOR_FORCE=1; fifi- # Always use --internal mode for directive support- wt_exec --internal "${args[@]}"+ # If --source was specified, use cargo run directly (builds and runs)+ if [[ "$use_source" == true ]]; then+ local script exit_code=0+ script="$(cargo run --quiet -- --internal "${args[@]}" 2>&2)" || exit_code=$?+ if [[ -n "$script" ]]; then+ eval "$script"+ if [[ $exit_code -eq 0 ]]; then+ exit_code=$?+ fi+ fi+ return "$exit_code"+ fi- # Restore original command- local result=$?- export WORKTRUNK_BIN="$saved_bin"- return $result+ wt_exec --internal "${args[@]}"}# Lazy completions - generate on first TAB, then delegate to clap's completerdiff --git a/templates/fish.fish b/templates/fish.fishindex 5e087831b..7c78dc51d 100644--- a/templates/fish.fish+++ b/templates/fish.fish@@ -32,7 +32,6 @@ if type -q {{ cmd_prefix }}; or set -q WORKTRUNK_BINfunction {{ cmd_prefix }}set -l use_source falseset -l args- set -l saved_bin $WORKTRUNK_BIN# Check for --source flag and strip itfor arg in $argv@@ -43,14 +42,6 @@ if type -q {{ cmd_prefix }}; or set -q WORKTRUNK_BINendend- # If --source was specified, build and use local debug binary- if test $use_source = true- if not cargo build --quiet- return 1- end- set -gx WORKTRUNK_BIN ./target/debug/{{ cmd_prefix }}- end-# Force colors if stderr is a TTY (directive mode outputs to stderr)# Respects NO_COLOR and explicit CLICOLOR_FORCEif not set -q NO_COLOR; and not set -q CLICOLOR_FORCE@@ -59,13 +50,20 @@ if type -q {{ cmd_prefix }}; or set -q WORKTRUNK_BINendend- # Always use --internal mode for directive support- wt_exec --internal $args+ # If --source was specified, use cargo run directly (builds and runs)+ if test $use_source = true+ set -l script (cargo run --quiet -- --internal $args 2>&2 | string collect)+ set -l exit_code $pipestatus[1]+ if test -n "$script"+ eval $script+ if test $exit_code -eq 0+ set exit_code $status+ end+ end+ return $exit_code+ end- # Restore original command- set -l result $status- set -gx WORKTRUNK_BIN $saved_bin- return $result+ wt_exec --internal $argsend# Completions are in ~/.config/fish/completions/wt.fish (installed by `wt config shell install`)diff --git a/templates/zsh.zsh b/templates/zsh.zshindex 8d9c16c47..975777c7e 100644--- a/templates/zsh.zsh+++ b/templates/zsh.zsh@@ -19,7 +19,6 @@ if command -v {{ cmd_prefix }} >/dev/null 2>&1 || [[ -n "${WORKTRUNK_BIN:-}" ]];local use_source=falselocal -a args- local saved_bin="$WORKTRUNK_BIN"# Check for --source flag and strip itfor arg in "$@"; do@@ -30,27 +29,26 @@ if command -v {{ cmd_prefix }} >/dev/null 2>&1 || [[ -n "${WORKTRUNK_BIN:-}" ]];fidone- # If --source was specified, build and use local debug binary- if [[ "$use_source" == true ]]; then- if ! cargo build --quiet; then- return 1- fi- export WORKTRUNK_BIN="./target/debug/{{ cmd_prefix }}"- fi-# Force colors if stderr is a TTY (directive mode outputs to stderr)# Respects NO_COLOR and explicit CLICOLOR_FORCEif [[ -z "${NO_COLOR:-}" && -z "${CLICOLOR_FORCE:-}" ]]; thenif [[ -t 2 ]]; then export CLICOLOR_FORCE=1; fifi- # Always use --internal mode for directive support- wt_exec --internal "${args[@]}"+ # If --source was specified, use cargo run directly (builds and runs)+ if [[ "$use_source" == true ]]; then+ local script exit_code=0+ script="$(cargo run --quiet -- --internal "${args[@]}" 2>&2)" || exit_code=$?+ if [[ -n "$script" ]]; then+ eval "$script"+ if [[ $exit_code -eq 0 ]]; then+ exit_code=$?+ fi+ fi+ return "$exit_code"+ fi- # Restore original command- local result=$?- export WORKTRUNK_BIN="$saved_bin"- return $result+ wt_exec --internal "${args[@]}"}# Lazy completions - generate on first TAB, then delegate to clap's completerdiff --git a/tests/snapshots/integration__integration_tests__init__init_bash.snap b/tests/snapshots/integration__integration_tests__init__init_bash.snapindex b8f8cbfe8..5b96a5d8c 100644--- a/tests/snapshots/integration__integration_tests__init__init_bash.snap+++ b/tests/snapshots/integration__integration_tests__init__init_bash.snap@@ -66,7 +66,6 @@ wt_exec() {local use_source=falselocal args=()- local saved_bin="$WORKTRUNK_BIN"# Check for --source flag and strip itfor arg in "$@"; do@@ -77,27 +76,26 @@ wt_exec() {fidone- # If --source was specified, build and use local debug binary- if [[ "$use_source" == true ]]; then- if ! cargo build --quiet; then- return 1- fi- export WORKTRUNK_BIN="./target/debug/wt"- fi-# Force colors if stderr is a TTY (directive mode outputs to stderr)# Respects NO_COLOR and explicit CLICOLOR_FORCEif [[ -z "${NO_COLOR:-}" && -z "${CLICOLOR_FORCE:-}" ]]; thenif [[ -t 2 ]]; then export CLICOLOR_FORCE=1; fifi- # Always use --internal mode for directive support- wt_exec --internal "${args[@]}"+ # If --source was specified, use cargo run directly (builds and runs)+ if [[ "$use_source" == true ]]; then+ local script exit_code=0+ script="$(cargo run --quiet -- --internal "${args[@]}" 2>&2)" || exit_code=$?+ if [[ -n "$script" ]]; then+ eval "$script"+ if [[ $exit_code -eq 0 ]]; then+ exit_code=$?+ fi+ fi+ return "$exit_code"+ fi- # Restore original command- local result=$?- export WORKTRUNK_BIN="$saved_bin"- return $result+ wt_exec --internal "${args[@]}"}# Lazy completions - generate on first TAB, then delegate to clap's completerdiff --git a/tests/snapshots/integration__integration_tests__init__init_fish.snap b/tests/snapshots/integration__integration_tests__init__init_fish.snapindex 735e8a9a4..4094584b3 100644--- a/tests/snapshots/integration__integration_tests__init__init_fish.snap+++ b/tests/snapshots/integration__integration_tests__init__init_fish.snap@@ -57,7 +57,6 @@ if type -q wt; or set -q WORKTRUNK_BINfunction wtset -l use_source falseset -l args- set -l saved_bin $WORKTRUNK_BIN# Check for --source flag and strip itfor arg in $argv@@ -68,14 +67,6 @@ if type -q wt; or set -q WORKTRUNK_BINendend- # If --source was specified, build and use local debug binary- if test $use_source = true- if not cargo build --quiet- return 1- end- set -gx WORKTRUNK_BIN ./target/debug/wt- end-# Force colors if stderr is a TTY (directive mode outputs to stderr)# Respects NO_COLOR and explicit CLICOLOR_FORCEif not set -q NO_COLOR; and not set -q CLICOLOR_FORCE@@ -84,13 +75,20 @@ if type -q wt; or set -q WORKTRUNK_BINendend- # Always use --internal mode for directive support- wt_exec --internal $args+ # If --source was specified, use cargo run directly (builds and runs)+ if test $use_source = true+ set -l script (cargo run --quiet -- --internal $args 2>&2 | string collect)+ set -l exit_code $pipestatus[1]+ if test -n "$script"+ eval $script+ if test $exit_code -eq 0+ set exit_code $status+ end+ end+ return $exit_code+ end- # Restore original command- set -l result $status- set -gx WORKTRUNK_BIN $saved_bin- return $result+ wt_exec --internal $argsend# Completions are in ~/.config/fish/completions/wt.fish (installed by `wt config shell install`)diff --git a/tests/snapshots/integration__integration_tests__init__init_zsh.snap b/tests/snapshots/integration__integration_tests__init__init_zsh.snapindex 801c35a7f..752571c66 100644--- a/tests/snapshots/integration__integration_tests__init__init_zsh.snap+++ b/tests/snapshots/integration__integration_tests__init__init_zsh.snap@@ -69,7 +69,6 @@ wt_exec() {local use_source=falselocal -a args- local saved_bin="$WORKTRUNK_BIN"# Check for --source flag and strip itfor arg in "$@"; do@@ -80,27 +79,26 @@ wt_exec() {fidone- # If --source was specified, build and use local debug binary- if [[ "$use_source" == true ]]; then- if ! cargo build --quiet; then- return 1- fi- export WORKTRUNK_BIN="./target/debug/wt"- fi-# Force colors if stderr is a TTY (directive mode outputs to stderr)# Respects NO_COLOR and explicit CLICOLOR_FORCEif [[ -z "${NO_COLOR:-}" && -z "${CLICOLOR_FORCE:-}" ]]; thenif [[ -t 2 ]]; then export CLICOLOR_FORCE=1; fifi- # Always use --internal mode for directive support- wt_exec --internal "${args[@]}"+ # If --source was specified, use cargo run directly (builds and runs)+ if [[ "$use_source" == true ]]; then+ local script exit_code=0+ script="$(cargo run --quiet -- --internal "${args[@]}" 2>&2)" || exit_code=$?+ if [[ -n "$script" ]]; then+ eval "$script"+ if [[ $exit_code -eq 0 ]]; then+ exit_code=$?+ fi+ fi+ return "$exit_code"+ fi- # Restore original command- local result=$?- export WORKTRUNK_BIN="$saved_bin"- return $result+ wt_exec --internal "${args[@]}"}# Lazy completions - generate on first TAB, then delegate to clap's completer