Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
Add --dev flag to shell integrations for local binary
Maximilian Roos12530281ba03
diff --git a/templates/bash.sh b/templates/bash.shindex 25164883a..cf621ac57 100644--- a/templates/bash.sh+++ b/templates/bash.sh@@ -54,19 +54,52 @@ if command -v wt >/dev/null 2>&1; then# Override {{ cmd_prefix }} command to add --internal flag for switch, remove, and merge{{ cmd_prefix }}() {- local subcommand="$1"-- case "$subcommand" in- switch|remove|merge)- # Commands that need --internal for directory change support- shift- _wt_exec --internal "$subcommand" "$@"- ;;- *)- # All other commands pass through directly- command "$_WORKTRUNK_CMD" "$@"- ;;- esac+ local use_dev=false+ local args=()+ local saved_cmd="$_WORKTRUNK_CMD"++ # Check for --dev flag and strip it+ for arg in "$@"; do+ if [[ "$arg" == "--dev" ]]; then+ use_dev=true+ else+ args+=("$arg")+ fi+ done++ # If --dev was specified, build and use local debug binary+ if [[ "$use_dev" == true ]]; then+ if ! cargo build --quiet >/dev/null 2>&1; then+ echo "Error: cargo build failed" >&2+ _WORKTRUNK_CMD="$saved_cmd"+ return 1+ fi+ _WORKTRUNK_CMD="./target/debug/wt"+ fi++ # Dispatch based on subcommand+ if [[ ${{ '{' }}#args[@]} -gt 0 ]]; then+ local subcommand="${args[0]}"++ case "$subcommand" in+ switch|remove|merge)+ # Commands that need --internal for directory change support+ _wt_exec --internal "${args[@]}"+ ;;+ *)+ # All other commands pass through directly+ command "$_WORKTRUNK_CMD" "${args[@]}"+ ;;+ esac+ else+ # No arguments, just run the command+ command "$_WORKTRUNK_CMD"+ fi++ # Restore original command+ local result=$?+ _WORKTRUNK_CMD="$saved_cmd"+ return $result}# Dynamic completion functiondiff --git a/templates/elvish.elv b/templates/elvish.elvindex b4d8198e4..b33c9c2a8 100644--- a/templates/elvish.elv+++ b/templates/elvish.elv@@ -55,20 +55,49 @@ if (has-external wt) {# Override {{ cmd_prefix }} command to add --internal flag for switch, remove, and mergefn {{ cmd_prefix }} {|@args|- if (== (count $args) 0) {+ var use-dev = $false+ var filtered-args = []+ var saved-cmd = $_WORKTRUNK_CMD++ # Check for --dev flag and strip it+ for arg $args {+ if (eq $arg "--dev") {+ set use-dev = $true+ } else {+ set filtered-args = [$@filtered-args $arg]+ }+ }++ # If --dev was specified, build and use local debug binary+ if $use-dev {+ try {+ e:cargo build --quiet 2>&1 | slurp+ } catch e {+ echo "Error: cargo build failed" >&2+ fail "cargo build failed"+ }+ set _WORKTRUNK_CMD = ./target/debug/wt+ }++ # Dispatch based on subcommand+ if (== (count $filtered-args) 0) {e:$_WORKTRUNK_CMD+ set _WORKTRUNK_CMD = $saved-cmdreturn}- var subcommand = $args[0]+ var subcommand = $filtered-args[0]if (or (eq $subcommand "switch") (eq $subcommand "remove") (eq $subcommand "merge")) {# Commands that need --internal for directory change support- var rest-args = $args[1..]+ var rest-args = $filtered-args[1..]_wt_exec --internal $subcommand $@rest-args} else {# All other commands pass through directly- e:$_WORKTRUNK_CMD $@args+ e:$_WORKTRUNK_CMD $@filtered-args}++ # Restore original command+ set _WORKTRUNK_CMD = $saved-cmd}}diff --git a/templates/fish.fish b/templates/fish.fishindex c9e737c4e..e16d99fa0 100644--- a/templates/fish.fish+++ b/templates/fish.fish@@ -92,16 +92,50 @@ if type -q {{ cmd_prefix }}# Override {{ cmd_prefix }} command to add --internal flag for switch, remove, and mergefunction {{ cmd_prefix }}- set -l subcommand $argv[1]-- switch $subcommand- case switch remove merge- # Commands that need --internal for directory change support- _wt_exec --internal $subcommand $argv[2..-1]- case '*'- # All other commands pass through directly- command $_WORKTRUNK_CMD $argv+ set -l use_dev false+ set -l args+ set -l saved_cmd $_WORKTRUNK_CMD++ # Check for --dev flag and strip it+ for arg in $argv+ if test "$arg" = "--dev"+ set use_dev true+ else+ set -a args $arg+ end+ end++ # If --dev was specified, build and use local debug binary+ if test $use_dev = true+ if not cargo build --quiet >/dev/null 2>&1+ echo "Error: cargo build failed" >&2+ set _WORKTRUNK_CMD $saved_cmd+ return 1+ end+ set _WORKTRUNK_CMD ./target/debug/wtend++ # Dispatch based on subcommand+ if test (count $args) -gt 0+ set -l subcommand $args[1]++ switch $subcommand+ case switch remove merge+ # Commands that need --internal for directory change support+ _wt_exec --internal $args+ case '*'+ # All other commands pass through directly+ command $_WORKTRUNK_CMD $args+ end+ else+ # No arguments, just run the command+ command $_WORKTRUNK_CMD+ end++ # Restore original command+ set -l result $status+ set _WORKTRUNK_CMD $saved_cmd+ return $resultend# Dynamic completion functiondiff --git a/templates/nushell.nu b/templates/nushell.nuindex 84f3607ad..4b0c2fa8f 100644--- a/templates/nushell.nu+++ b/templates/nushell.nu@@ -8,8 +8,9 @@ if (which wt | is-not-empty) {# Helper function to parse wt output and handle directives# Directives are NUL-terminated to support multi-line commands- export def --env _wt_exec [...args] {- let result = (do { ^$_WORKTRUNK_CMD ...$args } | complete)+ export def --env _wt_exec [cmd?: string, ...args] {+ let command = (if ($cmd | is-empty) { $_WORKTRUNK_CMD } else { $cmd })+ let result = (do { ^$command ...$args } | complete)mut exec_cmd = ""# Split output on NUL bytes, process each chunk@@ -41,19 +42,43 @@ if (which wt | is-not-empty) {# Override {{ cmd_prefix }} command to add --internal flag for switch, remove, and merge# Use --wrapped to pass through all flags without parsing themexport def --env --wrapped {{ cmd_prefix }} [...rest] {- let subcommand = ($rest | get 0? | default "")+ mut use_dev = false+ mut filtered_args = []++ # Check for --dev flag and strip it+ for arg in $rest {+ if $arg == "--dev" {+ $use_dev = true+ } else {+ $filtered_args = ($filtered_args | append $arg)+ }+ }++ # Determine which command to use+ let cmd = if $use_dev {+ let build_result = (do { cargo build --quiet } | complete)+ if $build_result.exit_code != 0 {+ print "Error: cargo build failed"+ return 1+ }+ "./target/debug/wt"+ } else {+ $_WORKTRUNK_CMD+ }++ let subcommand = ($filtered_args | get 0? | default "")match $subcommand {"switch" | "remove" | "merge" => {# Commands that need --internal for directory change support- let rest_args = ($rest | skip 1)+ let rest_args = ($filtered_args | skip 1)let internal_args = (["--internal", $subcommand] | append $rest_args)- let exit_code = (_wt_exec ...$internal_args)+ let exit_code = (_wt_exec $cmd ...$internal_args)return $exit_code}_ => {# All other commands pass through directly- ^$_WORKTRUNK_CMD ...$rest+ ^$cmd ...$filtered_args}}}diff --git a/templates/powershell.ps1 b/templates/powershell.ps1index 0432c0bee..3743d6aa5 100644--- a/templates/powershell.ps1+++ b/templates/powershell.ps1@@ -10,13 +10,17 @@ if (Get-Command wt -ErrorAction SilentlyContinue) {# Directives are NUL-terminated to support multi-line commandsfunction _wt_exec {param(+ [string]$Command,[Parameter(ValueFromRemainingArguments=$true)][string[]]$Arguments)+ # Use provided command or default to _WORKTRUNK_CMD+ $cmd = if ($Command) { $Command } else { $script:_WORKTRUNK_CMD }+# Capture stdout for directives, let stderr pass through to terminal# This preserves TTY for color detection- $output = & $script:_WORKTRUNK_CMD @Arguments | Out-String+ $output = & $cmd @Arguments | Out-String$exitCode = $LASTEXITCODE$execCmd = ""@@ -52,23 +56,48 @@ if (Get-Command wt -ErrorAction SilentlyContinue) {[string[]]$Arguments)- if ($Arguments.Count -eq 0) {- & $script:_WORKTRUNK_CMD+ $useDev = $false+ $filteredArgs = @()++ # Check for --dev flag and strip it+ foreach ($arg in $Arguments) {+ if ($arg -eq "--dev") {+ $useDev = $true+ } else {+ $filteredArgs += $arg+ }+ }++ # Determine which command to use+ if ($useDev) {+ # Build the project+ cargo build --quiet 2>&1 | Out-Null+ if ($LASTEXITCODE -ne 0) {+ Write-Error "Error: cargo build failed"+ return 1+ }+ $cmd = "./target/debug/wt"+ } else {+ $cmd = $script:_WORKTRUNK_CMD+ }++ if ($filteredArgs.Count -eq 0) {+ & $cmdreturn $LASTEXITCODE}- $subcommand = $Arguments[0]+ $subcommand = $filteredArgs[0]switch ($subcommand) {{ $_ -in @("switch", "remove", "merge") } {# Commands that need --internal for directory change support- $restArgs = $Arguments[1..($Arguments.Count-1)]- $exitCode = _wt_exec --internal $subcommand @restArgs+ $restArgs = $filteredArgs[1..($filteredArgs.Count-1)]+ $exitCode = _wt_exec -Command $cmd --internal $subcommand @restArgsreturn $exitCode}default {# All other commands pass through directly- & $script:_WORKTRUNK_CMD @Arguments+ & $cmd @filteredArgsreturn $LASTEXITCODE}}diff --git a/templates/xonsh.xsh b/templates/xonsh.xshindex bc6e1165e..4d08b2324 100644--- a/templates/xonsh.xsh+++ b/templates/xonsh.xsh@@ -3,16 +3,19 @@# Only initialize if wt is availableimport shutilimport os+import sysif shutil.which("wt") is not None:# Use WORKTRUNK_BIN if set, otherwise default to 'wt'# This allows testing development builds: $WORKTRUNK_BIN = ./target/debug/wt_WORKTRUNK_CMD = os.environ.get('WORKTRUNK_BIN', 'wt')- def _wt_exec(args):+ def _wt_exec(args, cmd=None):"""Helper function to parse wt output and handle directivesDirectives are NUL-terminated to support multi-line commands"""+ # Use provided command or default to _WORKTRUNK_CMD+ command = cmd if cmd is not None else _WORKTRUNK_CMD# Capture full output including return code- result = ![@(_WORKTRUNK_CMD) @(args)]+ result = ![@(command) @(args)]exec_cmd = ""# Split output on NUL bytes, process each chunk@@ -41,20 +44,41 @@ if shutil.which("wt") is not None:def _{{ cmd_prefix }}_wrapper(args):"""Override {{ cmd_prefix }} command to add --internal flag for switch, remove, and merge"""- if not args:- # No arguments, just run wt- ![@(_WORKTRUNK_CMD)]+ use_dev = False+ filtered_args = []++ # Check for --dev flag and strip it+ for arg in args:+ if arg == "--dev":+ use_dev = True+ else:+ filtered_args.append(arg)++ # Determine which command to use+ if use_dev:+ # Build the project+ build_result = !(cargo build --quiet)+ if build_result.returncode != 0:+ print("Error: cargo build failed", file=sys.stderr)+ return 1+ cmd = "./target/debug/wt"+ else:+ cmd = _WORKTRUNK_CMD++ if not filtered_args:+ # No arguments, just run the command+ ![@(cmd)]return- subcommand = args[0]+ subcommand = filtered_args[0]if subcommand in ["switch", "remove", "merge"]:# Commands that need --internal for directory change support- rest_args = args[1:]- return _wt_exec(["--internal", subcommand] + rest_args)+ rest_args = filtered_args[1:]+ return _wt_exec(["--internal", subcommand] + rest_args, cmd=cmd)else:# All other commands pass through directly- result = ![@(_WORKTRUNK_CMD) @(args)]+ result = ![@(cmd) @(filtered_args)]return result.returncode# Register the aliasdiff --git a/tests/snapshots/integration__integration_tests__init__init_bash.snap b/tests/snapshots/integration__integration_tests__init__init_bash.snapindex f823b237c..5ad7e7d95 100644--- a/tests/snapshots/integration__integration_tests__init__init_bash.snap+++ b/tests/snapshots/integration__integration_tests__init__init_bash.snap@@ -7,6 +7,7 @@ info:- bashenv:CLICOLOR_FORCE: "1"+ COLUMNS: "150"GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"GIT_CONFIG_GLOBAL: /dev/null@@ -15,7 +16,7 @@ info:LANG: CLC_ALL: CSOURCE_DATE_EPOCH: "1761609600"- WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpqU0guR/test-config.toml+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpUjqv7W/test-config.toml---success: trueexit_code: 0@@ -76,19 +77,52 @@ if command -v wt >/dev/null 2>&1; then# Override wt command to add --internal flag for switch, remove, and mergewt() {- local subcommand="$1"+ local use_dev=false+ local args=()+ local saved_cmd="$_WORKTRUNK_CMD"- case "$subcommand" in- switch|remove|merge)- # Commands that need --internal for directory change support- shift- _wt_exec --internal "$subcommand" "$@"- ;;- *)- # All other commands pass through directly- command "$_WORKTRUNK_CMD" "$@"- ;;- esac+ # Check for --dev flag and strip it+ for arg in "$@"; do+ if [[ "$arg" == "--dev" ]]; then+ use_dev=true+ else+ args+=("$arg")+ fi+ done++ # If --dev was specified, build and use local debug binary+ if [[ "$use_dev" == true ]]; then+ if ! cargo build --quiet >/dev/null 2>&1; then+ echo "Error: cargo build failed" >&2+ _WORKTRUNK_CMD="$saved_cmd"+ return 1+ fi+ _WORKTRUNK_CMD="./target/debug/wt"+ fi++ # Dispatch based on subcommand+ if [[ ${#args[@]} -gt 0 ]]; then+ local subcommand="${args[0]}"++ case "$subcommand" in+ switch|remove|merge)+ # Commands that need --internal for directory change support+ _wt_exec --internal "${args[@]}"+ ;;+ *)+ # All other commands pass through directly+ command "$_WORKTRUNK_CMD" "${args[@]}"+ ;;+ esac+ else+ # No arguments, just run the command+ command "$_WORKTRUNK_CMD"+ fi++ # Restore original command+ local result=$?+ _WORKTRUNK_CMD="$saved_cmd"+ return $result}# Dynamic completion functiondiff --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 cc8c224b8..b095266f1 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@@ -9,6 +9,7 @@ info:- wtenv:CLICOLOR_FORCE: "1"+ COLUMNS: "150"GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"GIT_CONFIG_GLOBAL: /dev/null@@ -17,7 +18,7 @@ info:LANG: CLC_ALL: CSOURCE_DATE_EPOCH: "1761609600"- WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpKlCu0A/test-config.toml+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpI2Bq3O/test-config.toml---success: trueexit_code: 0@@ -78,19 +79,52 @@ if command -v wt >/dev/null 2>&1; then# Override wt command to add --internal flag for switch, remove, and mergewt() {- local subcommand="$1"+ local use_dev=false+ local args=()+ local saved_cmd="$_WORKTRUNK_CMD"- case "$subcommand" in- switch|remove|merge)- # Commands that need --internal for directory change support- shift- _wt_exec --internal "$subcommand" "$@"- ;;- *)- # All other commands pass through directly- command "$_WORKTRUNK_CMD" "$@"- ;;- esac+ # Check for --dev flag and strip it+ for arg in "$@"; do+ if [[ "$arg" == "--dev" ]]; then+ use_dev=true+ else+ args+=("$arg")+ fi+ done++ # If --dev was specified, build and use local debug binary+ if [[ "$use_dev" == true ]]; then+ if ! cargo build --quiet >/dev/null 2>&1; then+ echo "Error: cargo build failed" >&2+ _WORKTRUNK_CMD="$saved_cmd"+ return 1+ fi+ _WORKTRUNK_CMD="./target/debug/wt"+ fi++ # Dispatch based on subcommand+ if [[ ${#args[@]} -gt 0 ]]; then+ local subcommand="${args[0]}"++ case "$subcommand" in+ switch|remove|merge)+ # Commands that need --internal for directory change support+ _wt_exec --internal "${args[@]}"+ ;;+ *)+ # All other commands pass through directly+ command "$_WORKTRUNK_CMD" "${args[@]}"+ ;;+ esac+ else+ # No arguments, just run the command+ command "$_WORKTRUNK_CMD"+ fi++ # Restore original command+ local result=$?+ _WORKTRUNK_CMD="$saved_cmd"+ return $result}# Dynamic completion functiondiff --git a/tests/snapshots/integration__integration_tests__init__init_fish.snap b/tests/snapshots/integration__integration_tests__init__init_fish.snapindex cd61879ed..72ac52b70 100644--- a/tests/snapshots/integration__integration_tests__init__init_fish.snap+++ b/tests/snapshots/integration__integration_tests__init__init_fish.snap@@ -7,6 +7,7 @@ info:- fishenv:CLICOLOR_FORCE: "1"+ COLUMNS: "150"GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"GIT_CONFIG_GLOBAL: /dev/null@@ -15,7 +16,7 @@ info:LANG: CLC_ALL: CSOURCE_DATE_EPOCH: "1761609600"- WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmp6EmXqA/test-config.toml+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpWc0lh5/test-config.toml---success: trueexit_code: 0@@ -114,16 +115,50 @@ if type -q wt# Override wt command to add --internal flag for switch, remove, and mergefunction wt- set -l subcommand $argv[1]-- switch $subcommand- case switch remove merge- # Commands that need --internal for directory change support- _wt_exec --internal $subcommand $argv[2..-1]- case '*'- # All other commands pass through directly- command $_WORKTRUNK_CMD $argv+ set -l use_dev false+ set -l args+ set -l saved_cmd $_WORKTRUNK_CMD++ # Check for --dev flag and strip it+ for arg in $argv+ if test "$arg" = "--dev"+ set use_dev true+ else+ set -a args $arg+ end+ end++ # If --dev was specified, build and use local debug binary+ if test $use_dev = true+ if not cargo build --quiet >/dev/null 2>&1+ echo "Error: cargo build failed" >&2+ set _WORKTRUNK_CMD $saved_cmd+ return 1+ end+ set _WORKTRUNK_CMD ./target/debug/wtend++ # Dispatch based on subcommand+ if test (count $args) -gt 0+ set -l subcommand $args[1]++ switch $subcommand+ case switch remove merge+ # Commands that need --internal for directory change support+ _wt_exec --internal $args+ case '*'+ # All other commands pass through directly+ command $_WORKTRUNK_CMD $args+ end+ else+ # No arguments, just run the command+ command $_WORKTRUNK_CMD+ end++ # Restore original command+ set -l result $status+ set _WORKTRUNK_CMD $saved_cmd+ return $resultend# Dynamic completion functiondiff --git a/tests/snapshots/integration__integration_tests__init__init_zsh.snap b/tests/snapshots/integration__integration_tests__init__init_zsh.snapindex 3388536ca..f1c1fea56 100644--- a/tests/snapshots/integration__integration_tests__init__init_zsh.snap+++ b/tests/snapshots/integration__integration_tests__init__init_zsh.snap@@ -7,6 +7,7 @@ info:- zshenv:CLICOLOR_FORCE: "1"+ COLUMNS: "150"GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"GIT_CONFIG_GLOBAL: /dev/null@@ -15,7 +16,7 @@ info:LANG: CLC_ALL: CSOURCE_DATE_EPOCH: "1761609600"- WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpnzShP2/test-config.toml+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpreSuwI/test-config.toml---success: trueexit_code: 0@@ -76,19 +77,52 @@ if command -v wt >/dev/null 2>&1; then# Override wt command to add --internal flag for switch, remove, and mergewt() {- local subcommand="$1"+ local use_dev=false+ local args=()+ local saved_cmd="$_WORKTRUNK_CMD"- case "$subcommand" in- switch|remove|merge)- # Commands that need --internal for directory change support- shift- _wt_exec --internal "$subcommand" "$@"- ;;- *)- # All other commands pass through directly- command "$_WORKTRUNK_CMD" "$@"- ;;- esac+ # Check for --dev flag and strip it+ for arg in "$@"; do+ if [[ "$arg" == "--dev" ]]; then+ use_dev=true+ else+ args+=("$arg")+ fi+ done++ # If --dev was specified, build and use local debug binary+ if [[ "$use_dev" == true ]]; then+ if ! cargo build --quiet >/dev/null 2>&1; then+ echo "Error: cargo build failed" >&2+ _WORKTRUNK_CMD="$saved_cmd"+ return 1+ fi+ _WORKTRUNK_CMD="./target/debug/wt"+ fi++ # Dispatch based on subcommand+ if [[ ${#args[@]} -gt 0 ]]; then+ local subcommand="${args[0]}"++ case "$subcommand" in+ switch|remove|merge)+ # Commands that need --internal for directory change support+ _wt_exec --internal "${args[@]}"+ ;;+ *)+ # All other commands pass through directly+ command "$_WORKTRUNK_CMD" "${args[@]}"+ ;;+ esac+ else+ # No arguments, just run the command+ command "$_WORKTRUNK_CMD"+ fi++ # Restore original command+ local result=$?+ _WORKTRUNK_CMD="$saved_cmd"+ return $result}# Dynamic completion function