---
source: tests/integration_tests/init.rs
info:
program: wt
args:
- config
- shell
- init
- bash
env:
APPDATA: "[TEST_CONFIG_HOME]"
CLICOLOR_FORCE: "1"
COLUMNS: "500"
GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
GIT_CONFIG_SYSTEM: /dev/null
GIT_EDITOR: ""
GIT_TERMINAL_PROMPT: "0"
HOME: "[TEST_HOME]"
LANG: C
LC_ALL: C
MOCK_CONFIG_DIR: "[MOCK_CONFIG_DIR]"
NO_COLOR: ""
OPENCODE_CONFIG_DIR: "[TEST_OPENCODE_CONFIG]"
PATH: "[PATH]"
PSModulePath: ""
RUST_LOG: warn
SHELL: ""
TERM: alacritty
USERPROFILE: "[TEST_HOME]"
WORKTRUNK_APPROVALS_PATH: "[TEST_APPROVALS]"
WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
WORKTRUNK_SYSTEM_CONFIG_PATH: "[TEST_SYSTEM_CONFIG]"
WORKTRUNK_TEST_CLAUDE_INSTALLED: "0"
WORKTRUNK_TEST_DELAYED_STREAM_MS: "-1"
WORKTRUNK_TEST_EPOCH: "1735776000"
WORKTRUNK_TEST_NUSHELL_ENV: "0"
WORKTRUNK_TEST_OPENCODE_INSTALLED: "0"
WORKTRUNK_TEST_POWERSHELL_ENV: "0"
WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"
XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"
---
success: true
exit_code: 0
----- stdout -----
# worktrunk shell integration for bash
# Only initialize if wt is available (in PATH or via WORKTRUNK_BIN)
if command -v wt >/dev/null 2>&1 || [[ -n "${WORKTRUNK_BIN:-}" ]]; then
# Override wt command with file-based directive passing.
# Creates a temp file, passes path via WORKTRUNK_DIRECTIVE_FILE, sources it after.
# WORKTRUNK_BIN can override the binary path (for testing dev builds).
wt() {
local use_source=false
local args=()
for arg in "$@"; do
if [[ "$arg" == "--source" ]]; then use_source=true; else args+=("$arg"); fi
done
# Completion mode: call binary directly, no directive file needed.
# This check MUST be here (not in the binary) because clap's completion
# handler runs before argument parsing.
if [[ -n "${COMPLETE:-}" ]]; then
command "${WORKTRUNK_BIN:-wt}" "${args[@]}"
return
fi
local directive_file exit_code=0
directive_file="$(mktemp)"
# --source: use cargo run (builds from source)
if [[ "$use_source" == true ]]; then
WORKTRUNK_DIRECTIVE_FILE="$directive_file" cargo run --bin wt --quiet -- "${args[@]}" || exit_code=$?
else
WORKTRUNK_DIRECTIVE_FILE="$directive_file" command "${WORKTRUNK_BIN:-wt}" "${args[@]}" || exit_code=$?
fi
if [[ -s "$directive_file" ]]; then
source "$directive_file"
if [[ $exit_code -eq 0 ]]; then
exit_code=$?
fi
fi
rm -f "$directive_file"
return "$exit_code"
}
# Lazy completions - generate on first TAB, then delegate to clap's completer
_wt_lazy_complete() {
# Generate completions function once (check if clap's function exists)
if ! declare -F _clap_complete_wt >/dev/null; then
# Use `command` to bypass the shell function and call the binary directly.
# Without this, `wt` would call the shell function which evals
# the completion script internally but doesn't re-emit it.
eval "$(COMPLETE=bash command "${WORKTRUNK_BIN:-wt}" 2>/dev/null)" || return
fi
_clap_complete_wt "$@"
}
complete -o nospace -o bashdefault -F _wt_lazy_complete wt
fi
----- stderr -----