Skip to content

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

Resolve `_WORKTRUNK_CMD` using `command -v`

Maximilian Roos77ccabd4b18c
diff --git a/templates/bash.sh b/templates/bash.sh
index 94adcdbe4..cf65ab815 100644
--- a/templates/bash.sh
+++ b/templates/bash.sh
@@ -2,9 +2,10 @@
# Only initialize if {{ cmd_prefix }} is available (in PATH or via WORKTRUNK_BIN)
if command -v {{ cmd_prefix }} >/dev/null 2>&1 || [[ -n "${WORKTRUNK_BIN:-}" ]]; then
- # Use WORKTRUNK_BIN if set, otherwise default to '{{ cmd_prefix }}'
+ # Use WORKTRUNK_BIN if set, otherwise resolve binary path
+ # Must resolve BEFORE defining shell function, so lazy completion can call binary directly
# This allows testing development builds: export WORKTRUNK_BIN=./target/debug/{{ cmd_prefix }}
- _WORKTRUNK_CMD="${WORKTRUNK_BIN:-{{ cmd_prefix }}}"
+ _WORKTRUNK_CMD="${WORKTRUNK_BIN:-$(command -v {{ cmd_prefix }})}"
{{ posix_shim }}
@@ -12,7 +13,7 @@ if command -v {{ cmd_prefix }} >/dev/null 2>&1 || [[ -n "${WORKTRUNK_BIN:-}" ]];
{{ cmd_prefix }}() {
# Initialize _WORKTRUNK_CMD if not set (e.g., after shell snapshot restore)
if [[ -z "$_WORKTRUNK_CMD" ]]; then
- _WORKTRUNK_CMD="${WORKTRUNK_BIN:-{{ cmd_prefix }}}"
+ _WORKTRUNK_CMD="${WORKTRUNK_BIN:-$(command -v {{ cmd_prefix }})}"
fi
local use_source=false
diff --git a/templates/zsh.zsh b/templates/zsh.zsh
index 8b7296015..9af17dea9 100644
--- a/templates/zsh.zsh
+++ b/templates/zsh.zsh
@@ -2,9 +2,10 @@
# Only initialize if {{ cmd_prefix }} is available (in PATH or via WORKTRUNK_BIN)
if command -v {{ cmd_prefix }} >/dev/null 2>&1 || [[ -n "${WORKTRUNK_BIN:-}" ]]; then
- # Use WORKTRUNK_BIN if set, otherwise default to '{{ cmd_prefix }}'
+ # Use WORKTRUNK_BIN if set, otherwise resolve binary path
+ # Must resolve BEFORE defining shell function, so lazy completion can call binary directly
# This allows testing development builds: export WORKTRUNK_BIN=./target/debug/{{ cmd_prefix }}
- _WORKTRUNK_CMD="${WORKTRUNK_BIN:-{{ cmd_prefix }}}"
+ _WORKTRUNK_CMD="${WORKTRUNK_BIN:-$(command -v {{ cmd_prefix }})}"
{{ posix_shim }}
@@ -12,7 +13,7 @@ if command -v {{ cmd_prefix }} >/dev/null 2>&1 || [[ -n "${WORKTRUNK_BIN:-}" ]];
{{ cmd_prefix }}() {
# Initialize _WORKTRUNK_CMD if not set (e.g., after shell snapshot restore)
if [[ -z "$_WORKTRUNK_CMD" ]]; then
- _WORKTRUNK_CMD="${WORKTRUNK_BIN:-{{ cmd_prefix }}}"
+ _WORKTRUNK_CMD="${WORKTRUNK_BIN:-$(command -v {{ cmd_prefix }})}"
fi
local use_source=false
diff --git a/tests/snapshots/integration__integration_tests__init__init_bash.snap b/tests/snapshots/integration__integration_tests__init__init_bash.snap
index e749bf8eb..d2e6d8260 100644
--- a/tests/snapshots/integration__integration_tests__init__init_bash.snap
+++ b/tests/snapshots/integration__integration_tests__init__init_bash.snap
@@ -27,9 +27,10 @@ exit_code: 0
# Only initialize if wt is available (in PATH or via WORKTRUNK_BIN)
if command -v wt >/dev/null 2>&1 || [[ -n "${WORKTRUNK_BIN:-}" ]]; then
- # Use WORKTRUNK_BIN if set, otherwise default to 'wt'
+ # Use WORKTRUNK_BIN if set, otherwise resolve binary path
+ # Must resolve BEFORE defining shell function, so lazy completion can call binary directly
# This allows testing development builds: export WORKTRUNK_BIN=./target/debug/wt
- _WORKTRUNK_CMD="${WORKTRUNK_BIN:-wt}"
+ _WORKTRUNK_CMD="${WORKTRUNK_BIN:-$(command -v wt)}"
# Shared directive parser for POSIX shells (bash, zsh, oil).
# Streams worktrunk's NUL-delimited output in real-time via FIFO while keeping
@@ -124,7 +125,7 @@ wt_exec() {
wt() {
# Initialize _WORKTRUNK_CMD if not set (e.g., after shell snapshot restore)
if [[ -z "$_WORKTRUNK_CMD" ]]; then
- _WORKTRUNK_CMD="${WORKTRUNK_BIN:-wt}"
+ _WORKTRUNK_CMD="${WORKTRUNK_BIN:-$(command -v wt)}"
fi
local use_source=false
diff --git a/tests/snapshots/integration__integration_tests__init__init_zsh.snap b/tests/snapshots/integration__integration_tests__init__init_zsh.snap
index b69e7e931..738fbcee8 100644
--- a/tests/snapshots/integration__integration_tests__init__init_zsh.snap
+++ b/tests/snapshots/integration__integration_tests__init__init_zsh.snap
@@ -27,9 +27,10 @@ exit_code: 0
# Only initialize if wt is available (in PATH or via WORKTRUNK_BIN)
if command -v wt >/dev/null 2>&1 || [[ -n "${WORKTRUNK_BIN:-}" ]]; then
- # Use WORKTRUNK_BIN if set, otherwise default to 'wt'
+ # Use WORKTRUNK_BIN if set, otherwise resolve binary path
+ # Must resolve BEFORE defining shell function, so lazy completion can call binary directly
# This allows testing development builds: export WORKTRUNK_BIN=./target/debug/wt
- _WORKTRUNK_CMD="${WORKTRUNK_BIN:-wt}"
+ _WORKTRUNK_CMD="${WORKTRUNK_BIN:-$(command -v wt)}"
# Shared directive parser for POSIX shells (bash, zsh, oil).
# Streams worktrunk's NUL-delimited output in real-time via FIFO while keeping
@@ -124,7 +125,7 @@ wt_exec() {
wt() {
# Initialize _WORKTRUNK_CMD if not set (e.g., after shell snapshot restore)
if [[ -z "$_WORKTRUNK_CMD" ]]; then
- _WORKTRUNK_CMD="${WORKTRUNK_BIN:-wt}"
+ _WORKTRUNK_CMD="${WORKTRUNK_BIN:-$(command -v wt)}"
fi
local use_source=false