---
source: src/shell/mod.rs
expression: output
---
# worktrunk shell integration for fish
#
# This is the full function definition, output by `wt config shell init fish`.
# It's sourced at runtime by the wrapper in ~/.config/fish/functions/wt.fish.
# Override wt command with file-based directive passing.
# Creates a temp file, passes path via WORKTRUNK_DIRECTIVE_FILE, evals it after.
# WORKTRUNK_BIN can override the binary path (for testing dev builds).
#
# Note: We use `eval (string collect < file)` instead of `source` because
# fish's `source` doesn't propagate exit codes to the parent function.
# We read the directive with `string collect` (builtin) instead of `cat`
# (external) to avoid spawning a subprocess whose CWD may have been renamed
# by worktree removal.
function wt
set -l use_source false
set -l args
for arg in $argv
if test "$arg" = "--source"; set use_source true; else; set -a args $arg; end
end
test -n "$WORKTRUNK_BIN"; or set -l WORKTRUNK_BIN (type -P wt 2>/dev/null)
if test -z "$WORKTRUNK_BIN"
echo "wt: command not found" >&2
return 127
end
set -l directive_file (mktemp)
# --source: use cargo run (builds from source)
if test $use_source = true
env WORKTRUNK_DIRECTIVE_FILE=$directive_file cargo run --bin wt --quiet -- $args
else
env WORKTRUNK_DIRECTIVE_FILE=$directive_file $WORKTRUNK_BIN $args
end
set -l exit_code $status
if test -s "$directive_file"
# Use fish builtin instead of cat to avoid spawning a subprocess
# whose CWD may have been renamed by worktree removal.
set -l directive (string collect < "$directive_file")
eval $directive
if test $exit_code -eq 0
set exit_code $status
end
end
command rm -f "$directive_file"
return $exit_code
end
# Completions are in ~/.config/fish/completions/wt.fish (installed by `wt config shell install`)