Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
Improve Bash/Zsh lazy completion for `config shell init`
Maximilian Roos35766787c565
diff --git a/src/cli.rs b/src/cli.rsindex b2cad5eb5..5e60f330b 100644--- a/src/cli.rs+++ b/src/cli.rs@@ -232,15 +232,15 @@ Detects various forms of the integration pattern regardless of:/// Generate shell completion script#[command(after_long_help = r#"## Usage-Generate completions for your shell:+Generate completions for manual shell setup:```console-wt config shell completions zsh > ~/.zfunc/_wt+wt config shell completions fish > ~/.config/fish/completions/wt.fish```-This outputs a script that calls back to `wt` for dynamic completions-(branch names, worktrees, etc.). The script is designed for fpath-autoloading - zsh loads it only on first completion attempt."#)]+Note: Bash and Zsh completions are automatically included via+`wt config shell install` using inline lazy loading. This command+is primarily for Fish or manual configuration."#)]Completions {/// Shell to generate completions for#[arg(value_enum)]diff --git a/src/commands/configure_shell.rs b/src/commands/configure_shell.rsindex 2c2df4496..785b1da1f 100644--- a/src/commands/configure_shell.rs+++ b/src/commands/configure_shell.rs@@ -23,7 +23,10 @@ pub struct UninstallResult {pub struct UninstallScanResult {pub results: Vec<UninstallResult>,pub completion_results: Vec<CompletionUninstallResult>,+ /// Shell extensions not found (bash/zsh show as "integration", fish as "shell extension")pub not_found: Vec<(Shell, PathBuf)>,+ /// Completion files not found (only fish has separate completion files)+ pub completion_not_found: Vec<(Shell, PathBuf)>,}pub struct CompletionUninstallResult {@@ -450,9 +453,15 @@ fn prompt_for_confirmation(let shell = result.shell;let path = format_path_for_display(&result.path);+ // For bash/zsh, completions are inline in the init script+ let what = if matches!(shell, Shell::Bash | Shell::Zsh) {+ "shell extension & completions"+ } else {+ "shell extension"+ };eprintln!(- "{} {} shell extension for {bold}{shell}{bold:#} @ {bold}{path}{bold:#}",+ "{} {} {what} for {bold}{shell}{bold:#} @ {bold}{path}{bold:#}",result.action.emoji(),result.action.description(),);@@ -462,7 +471,7 @@ fn prompt_for_confirmation(eprintln!(); // Blank line after each shell block}- // Show completion changes+ // Show completion changes (only fish has separate completion files)for result in completion_results {if matches!(result.action, ConfigAction::AlreadyExists) {continue;@@ -476,6 +485,16 @@ fn prompt_for_confirmation(result.action.emoji(),result.action.description(),);++ // Show what will be created (dynamic completions generated by clap)+ eprint!(+ "{}",+ format_bash_with_gutter(+ &format!("# Dynamic completions generated by: wt config shell completions {shell}"),+ ""+ )+ );+ eprintln!(); // Blank line after}prompt_yes_no()@@ -504,8 +523,9 @@ fn prompt_yes_no() -> Result<bool, String> {/// Process shell completions - either preview or write based on dry_run flag///-/// Note: Zsh completions are handled via lazy `compdef` in the init script,-/// so we skip writing static completion files for zsh.+/// Note: Bash and Zsh completions are handled via lazy loading in the init script,+/// so we only write static completion files for Fish (which uses native lazy loading+/// from ~/.config/fish/completions/).fn process_shell_completions(shells: &[Shell],dry_run: bool,@@ -513,8 +533,8 @@ fn process_shell_completions(let mut results = Vec::new();for &shell in shells {- // Skip zsh - completions are handled via lazy compdef in the init script- if matches!(shell, Shell::Zsh) {+ // Skip bash/zsh - completions are handled via lazy loading in the init script+ if matches!(shell, Shell::Bash | Shell::Zsh) {continue;}let completion_path = shell@@ -637,6 +657,7 @@ fn scan_for_uninstall(let mut results = Vec::new();let mut not_found = Vec::new();+ let mut completion_not_found = Vec::new();for &shell in &shells {let paths = shell@@ -702,8 +723,8 @@ fn scan_for_uninstall(let mut completion_results = Vec::new();for &shell in &shells {- // Skip zsh - completions are handled via lazy compdef in the init script- if matches!(shell, Shell::Zsh) {+ // Skip bash/zsh - completions are handled via lazy loading in the init script+ if matches!(shell, Shell::Bash | Shell::Zsh) {continue;}@@ -731,6 +752,8 @@ fn scan_for_uninstall(action: UninstallAction::Removed,});}+ } else {+ completion_not_found.push((shell, completion_path));}}@@ -738,6 +761,7 @@ fn scan_for_uninstall(results,completion_results,not_found,+ completion_not_found,})}@@ -810,9 +834,15 @@ fn prompt_for_uninstall_confirmation(let bold = Style::new().bold();let shell = result.shell;let path = format_path_for_display(&result.path);+ // For bash/zsh, completions are inline in the init script+ let what = if matches!(shell, Shell::Bash | Shell::Zsh) {+ "shell extension & completions"+ } else {+ "shell extension"+ };eprintln!(- "{} {} shell extension for {bold}{shell}{bold:#} @ {bold}{path}{bold:#}",+ "{} {} {what} for {bold}{shell}{bold:#} @ {bold}{path}{bold:#}",result.action.emoji(),result.action.description(),);diff --git a/src/main.rs b/src/main.rsindex e6461cc14..ea5c09aff 100644--- a/src/main.rs+++ b/src/main.rs@@ -226,8 +226,14 @@ fn main() {for result in &scan_result.configured {let shell = result.shell;let path = format_path_for_display(&result.path);+ // For bash/zsh, completions are inline in the init script+ let what = if matches!(shell, worktrunk::shell::Shell::Bash | worktrunk::shell::Shell::Zsh) {+ "shell extension & completions"+ } else {+ "shell extension"+ };let message = format!(- "{} shell extension for {bold}{shell}{bold:#} @ {bold}{path}{bold:#}",+ "{} {what} for {bold}{shell}{bold:#} @ {bold}{path}{bold:#}",result.action.description());@@ -276,14 +282,6 @@ fn main() {crate::output::progress(comp_message)?;}}- } else if matches!(shell, worktrunk::shell::Shell::Zsh)- && !matches!(result.action, ConfigAction::AlreadyExists)- {- // Zsh completions are handled via lazy compdef in the init script- // Only show this message for new installations- crate::output::info(format!(- "Completions for {bold}zsh{bold:#} via lazy compdef (no file needed)"- ))?;}}@@ -300,19 +298,12 @@ fn main() {return Err(anyhow::anyhow!("No shell config files found"));}- // Count total changes (config + completions)- let completion_changes = scan_result.completion_results- .iter()- .filter(|r| !matches!(r.action, ConfigAction::AlreadyExists))- .count();- let total_changes = changes_count + completion_changes;-- // Summary- if total_changes > 0 {+ // Summary (count shells, not files - fish has both conf.d and completions)+ if changes_count > 0 {crate::output::blank()?;- let plural = if total_changes == 1 { "" } else { "s" };+ let plural = if changes_count == 1 { "" } else { "s" };crate::output::success(format!(- "Configured {total_changes} shell{plural}"+ "Configured {changes_count} shell{plural}"))?;} else {crate::output::success("All shells already configured")?;@@ -324,7 +315,7 @@ fn main() {.ok().and_then(|s| s.rsplit('/').next().map(String::from));- let current_shell_path =+ let current_shell_result =current_shell.as_ref().and_then(|shell_name| {scan_result.configured@@ -335,13 +326,19 @@ fn main() {.find(|r| {r.shell.to_string().eq_ignore_ascii_case(shell_name)})- .map(|r| format_path_for_display(&r.path))});- if let Some(path) = current_shell_path {- crate::output::hint(format!(- "Restart shell or run: source {path}"- ))?;+ if let Some(result) = current_shell_result {+ // Fish auto-sources from conf.d, so just say "Restart shell"+ // Bash/Zsh can source directly for immediate activation+ if matches!(result.shell, worktrunk::shell::Shell::Fish) {+ crate::output::hint("Restart shell to activate")?;+ } else {+ let path = format_path_for_display(&result.path);+ crate::output::hint(format!(+ "Restart shell or run: source {path}"+ ))?;+ }}}Ok(())@@ -361,9 +358,15 @@ fn main() {let bold = Style::new().bold();let shell = result.shell;let path = format_path_for_display(&result.path);+ // For bash/zsh, completions are inline in the init script+ let what = if matches!(shell, worktrunk::shell::Shell::Bash | worktrunk::shell::Shell::Zsh) {+ "shell extension & completions"+ } else {+ "shell extension"+ };crate::output::success(format!(- "{} shell extension for {bold}{shell}{bold:#} @ {bold}{path}{bold:#}",+ "{} {what} for {bold}{shell}{bold:#} @ {bold}{path}{bold:#}",result.action.description(),))?;}@@ -380,38 +383,50 @@ fn main() {))?;}- // Show zsh lazy compdef message if zsh shell extension was removed- // but no completion file was removed (because zsh uses lazy compdef)- let bold = Style::new().bold();- let zsh_shell_removed = scan_result.results.iter().any(|r| {- matches!(r.shell, worktrunk::shell::Shell::Zsh)- });- let zsh_completion_removed = scan_result.completion_results.iter().any(|r| {- matches!(r.shell, worktrunk::shell::Shell::Zsh)- });- if zsh_shell_removed && !zsh_completion_removed {- crate::output::info(format!(- "Completions for {bold}zsh{bold:#} were via lazy compdef (no file to remove)"- ))?;- }-// Show not found - warning if explicit shell, hint if auto-scanfor (shell, path) in &scan_result.not_found {+ let path = format_path_for_display(path);+ // Use consistent terminology matching install/uninstall messages+ let what = if matches!(shell, worktrunk::shell::Shell::Bash | worktrunk::shell::Shell::Zsh) {+ "shell extension & completions"+ } else {+ "shell extension"+ };+ if explicit_shell {+ crate::output::warning(format!(+ "No {what} found in {path}"+ ))?;+ } else {+ crate::output::hint(format!(+ "No {shell} {what} in {path}"+ ))?;+ }+ }++ // Show completion files not found (only fish has separate completion files)+ // Only show this if the shell extension was ALSO not found - if we removed+ // the shell extension, no need to warn about missing completions+ for (shell, path) in &scan_result.completion_not_found {+ let shell_was_removed = scan_result.results.iter().any(|r| r.shell == *shell);+ if shell_was_removed {+ continue; // Shell extension was removed, don't warn about completions+ }let path = format_path_for_display(path);if explicit_shell {crate::output::warning(format!(- "No shell integration found in {path}"+ "No completions found in {path}"))?;} else {crate::output::hint(format!(- "No {shell} integration in {path}"+ "No {shell} completions in {path}"))?;}}// Exit with info if nothing was found+ let all_not_found = scan_result.not_found.len() + scan_result.completion_not_found.len();if total_changes == 0 {- if scan_result.not_found.is_empty() {+ if all_not_found == 0 {crate::output::blank()?;crate::output::hint("No shell integration found to remove",diff --git a/src/shell.rs b/src/shell.rsindex 1ce329b2d..76a9a86a9 100644--- a/src/shell.rs+++ b/src/shell.rs@@ -103,10 +103,11 @@ impl Shell {/// Returns the path to the native completion directory for this shell///- /// These are the standard locations where shells look for lazy-loaded completions:- /// - Bash: `~/.local/share/bash-completion/completions/`- /// - Zsh: `~/.zfunc/` (for manual setup only; install uses lazy compdef)- /// - Fish: `~/.config/fish/completions/`+ /// Note: Only Fish uses static completion files. Bash and Zsh use inline+ /// lazy loading in the init script, so these paths are for reference only:+ /// - Bash: `~/.local/share/bash-completion/completions/` (not used by install)+ /// - Zsh: `~/.zfunc/` (not used by install)+ /// - Fish: `~/.config/fish/completions/` (used by install)pub fn completion_path(&self) -> Result<PathBuf, std::io::Error> {let home = home_dir()?;diff --git a/templates/bash.sh b/templates/bash.shindex 63cfe3871..67cbaa3f0 100644--- a/templates/bash.sh+++ b/templates/bash.sh@@ -53,6 +53,14 @@ if command -v {{ cmd_prefix }} >/dev/null 2>&1 || [[ -n "${WORKTRUNK_BIN:-}" ]];return $result}- # Completions are loaded from ~/.local/share/bash-completion/completions/wt- # Install with: wt config shell install+ # Lazy completions - generate on first TAB, then delegate to clap's completer+ _{{ cmd_prefix }}_lazy_complete() {+ # Generate completions function once (check if clap's function exists)+ if ! declare -F _clap_complete_{{ cmd_prefix }} >/dev/null; then+ eval "$(COMPLETE=bash "$_WORKTRUNK_CMD" 2>/dev/null)" || return+ fi+ _clap_complete_{{ cmd_prefix }} "$@"+ }++ complete -o nospace -o bashdefault -F _{{ cmd_prefix }}_lazy_complete {{ cmd_prefix }}fidiff --git a/templates/zsh.zsh b/templates/zsh.zshindex 6cb68e27a..1e57e576a 100644--- a/templates/zsh.zsh+++ b/templates/zsh.zsh@@ -53,24 +53,21 @@ if command -v {{ cmd_prefix }} >/dev/null 2>&1 || [[ -n "${WORKTRUNK_BIN:-}" ]];return $result}- # Lazy completions via compdef - no fpath setup needed- # Regenerates on first TAB in each shell session- if (( $+functions[compdef] )); then- _{{ cmd_prefix }}_lazy_complete() {- # Load dynamic completion script once- unfunction _{{ cmd_prefix }}_lazy_complete 2>/dev/null || true-- # Generate & eval the real completer from the binary- local _script- _script="$(COMPLETE=zsh "$_WORKTRUNK_CMD" 2>/dev/null)" || return- eval "$_script"-- # Delegate to clap's generated function- if (( $+functions[_clap_dynamic_completer_{{ cmd_prefix }}] )); then- _clap_dynamic_completer_{{ cmd_prefix }} "$@"- fi- }+ # Lazy completions - generate on first TAB, then delegate to clap's completer+ # NOTE: This must come AFTER compinit in your .zshrc+ _{{ cmd_prefix }}_lazy_complete() {+ # Generate completions function once (check if clap's function exists)+ if ! (( $+functions[_clap_dynamic_completer_{{ cmd_prefix }}] )); then+ eval "$(COMPLETE=zsh "$_WORKTRUNK_CMD" 2>/dev/null)" || return+ fi+ _clap_dynamic_completer_{{ cmd_prefix }} "$@"+ }+ # Register completion (requires compinit to have run first)+ if (( $+functions[compdef] )); thencompdef _{{ cmd_prefix }}_lazy_complete {{ cmd_prefix }}+ else+ echo "{{ cmd_prefix }}: completions disabled (compinit not loaded yet)" >&2+ echo "{{ cmd_prefix }}: move 'eval \"\$({{ cmd_prefix }} config shell init zsh)\"' after compinit in your .zshrc" >&2fifidiff --git a/tests/integration_tests/configure_shell.rs b/tests/integration_tests/configure_shell.rsindex 1be03f2ab..a8467dabf 100644--- a/tests/integration_tests/configure_shell.rs+++ b/tests/integration_tests/configure_shell.rs@@ -29,8 +29,7 @@ fn test_configure_shell_with_yes() {success: trueexit_code: 0----- stdout ------ ✅ Added shell extension for [1mzsh[0m @ [1m~/.zshrc[0m- ⚪ Completions for [1mzsh[0m via lazy compdef (no file needed)+ ✅ Added shell extension & completions for [1mzsh[0m @ [1m~/.zshrc[0m💡 [2mSkipped [1mbash[0m; ~/.bashrc not found[0m💡 [2mSkipped [1mfish[0m; ~/.config/fish/conf.d not found[0m@@ -73,8 +72,7 @@ fn test_configure_shell_specific_shell() {success: trueexit_code: 0----- stdout ------ ✅ Added shell extension for [1mzsh[0m @ [1m~/.zshrc[0m- ⚪ Completions for [1mzsh[0m via lazy compdef (no file needed)+ ✅ Added shell extension & completions for [1mzsh[0m @ [1m~/.zshrc[0m✅ Configured 1 shell💡 [2mRestart shell or run: source ~/.zshrc[0m@@ -119,7 +117,7 @@ fn test_configure_shell_already_exists() {success: trueexit_code: 0----- stdout ------ ⚪ Already configured shell extension for [1mzsh[0m @ [1m~/.zshrc[0m+ ⚪ Already configured shell extension & completions for [1mzsh[0m @ [1m~/.zshrc[0m✅ All shells already configured----- stderr -----@@ -158,8 +156,8 @@ fn test_configure_shell_fish() {✅ Created shell extension for [1mfish[0m @ [1m~/.config/fish/conf.d/wt.fish[0m✅ Created completions for [1mfish[0m @ [1m~/.config/fish/completions/wt.fish[0m- ✅ Configured 2 shells- 💡 [2mRestart shell or run: source ~/.config/fish/conf.d/wt.fish[0m+ ✅ Configured 1 shell+ 💡 [2mRestart shell to activate[0m----- stderr -----");@@ -237,13 +235,11 @@ fn test_configure_shell_multiple_configs() {success: trueexit_code: 0----- stdout ------ ✅ Added shell extension for [1mbash[0m @ [1m~/.bashrc[0m- ✅ Created completions for [1mbash[0m @ [1m~/.local/share/bash-completion/completions/wt[0m- ✅ Added shell extension for [1mzsh[0m @ [1m~/.zshrc[0m- ⚪ Completions for [1mzsh[0m via lazy compdef (no file needed)+ ✅ Added shell extension & completions for [1mbash[0m @ [1m~/.bashrc[0m+ ✅ Added shell extension & completions for [1mzsh[0m @ [1m~/.zshrc[0m💡 [2mSkipped [1mfish[0m; ~/.config/fish/conf.d not found[0m- ✅ Configured 3 shells+ ✅ Configured 2 shells💡 [2mRestart shell or run: source ~/.zshrc[0m----- stderr -----@@ -298,13 +294,11 @@ fn test_configure_shell_mixed_states() {success: trueexit_code: 0----- stdout ------ ⚪ Already configured shell extension for [1mbash[0m @ [1m~/.bashrc[0m- ✅ Created completions for [1mbash[0m @ [1m~/.local/share/bash-completion/completions/wt[0m- ✅ Added shell extension for [1mzsh[0m @ [1m~/.zshrc[0m- ⚪ Completions for [1mzsh[0m via lazy compdef (no file needed)+ ⚪ Already configured shell extension & completions for [1mbash[0m @ [1m~/.bashrc[0m+ ✅ Added shell extension & completions for [1mzsh[0m @ [1m~/.zshrc[0m💡 [2mSkipped [1mfish[0m; ~/.config/fish/conf.d not found[0m- ✅ Configured 2 shells+ ✅ Configured 1 shell💡 [2mRestart shell or run: source ~/.zshrc[0m----- stderr -----@@ -357,10 +351,10 @@ fn test_uninstall_shell() {success: trueexit_code: 0----- stdout ------ ✅ Removed shell extension for [1mzsh[0m @ [1m~/.zshrc[0m- ⚪ Completions for [1mzsh[0m were via lazy compdef (no file to remove)- 💡 [2mNo bash integration in ~/.bashrc[0m- 💡 [2mNo fish integration in ~/.config/fish/conf.d/wt.fish[0m+ ✅ Removed shell extension & completions for [1mzsh[0m @ [1m~/.zshrc[0m+ 💡 [2mNo bash shell extension & completions in ~/.bashrc[0m+ 💡 [2mNo fish shell extension in ~/.config/fish/conf.d/wt.fish[0m+ 💡 [2mNo fish completions in ~/.config/fish/completions/wt.fish[0m✅ Removed integration from 1 shell💡 [2mRestart shell to complete uninstall[0m@@ -417,10 +411,10 @@ fn test_uninstall_shell_multiple() {success: trueexit_code: 0----- stdout ------ ✅ Removed shell extension for [1mbash[0m @ [1m~/.bashrc[0m- ✅ Removed shell extension for [1mzsh[0m @ [1m~/.zshrc[0m- ⚪ Completions for [1mzsh[0m were via lazy compdef (no file to remove)- 💡 [2mNo fish integration in ~/.config/fish/conf.d/wt.fish[0m+ ✅ Removed shell extension & completions for [1mbash[0m @ [1m~/.bashrc[0m+ ✅ Removed shell extension & completions for [1mzsh[0m @ [1m~/.zshrc[0m+ 💡 [2mNo fish shell extension in ~/.config/fish/conf.d/wt.fish[0m+ 💡 [2mNo fish completions in ~/.config/fish/completions/wt.fish[0m✅ Removed integration from 2 shells💡 [2mRestart shell to complete uninstall[0m@@ -470,7 +464,7 @@ fn test_uninstall_shell_not_found() {success: trueexit_code: 0----- stdout ------ 🟡 No shell integration found in ~/.zshrc+ 🟡 No shell extension & completions found in ~/.zshrc----- stderr -----");diff --git a/tests/integration_tests/shell_wrapper.rs b/tests/integration_tests/shell_wrapper.rsindex 5f090052b..45178022a 100644--- a/tests/integration_tests/shell_wrapper.rs+++ b/tests/integration_tests/shell_wrapper.rs@@ -1607,6 +1607,7 @@ approved-commands = ["echo 'bash background'"]// ========================================================================/// Test that bash completions are properly registered+ /// Note: Completions are inline in the wrapper script (lazy loading)#[test]fn test_bash_completions_registered() {let repo = TestRepo::new();@@ -1614,22 +1615,20 @@ approved-commands = ["echo 'bash background'"]let wt_bin = get_cargo_bin("wt");let wrapper_script = generate_wrapper(&repo, "bash");- let completions_script = generate_completions(&repo, "bash");- // Script that sources wrapper, completions, and checks if completion is registered+ // Script that sources wrapper and checks if completion is registered+ // (completions are inline in the wrapper via lazy loading)let script = format!(r#"export WORKTRUNK_BIN='{}'export WORKTRUNK_CONFIG_PATH='{}'{}- {}# Check if wt completion is registeredcomplete -p wt 2>/dev/null && echo "__COMPLETION_REGISTERED__" || echo "__NO_COMPLETION__""#,wt_bin.display(),repo.test_config_path().display(),- wrapper_script,- completions_script+ wrapper_script);let final_script = format!("( {} ) 2>&1", script);@@ -1695,7 +1694,7 @@ approved-commands = ["echo 'bash background'"]}/// Test that zsh wrapper function is properly defined- /// Note: Completions come from fpath (~/.zfunc/_wt), not from the wrapper+ /// Note: Completions are inline in the wrapper script (lazy loading via compdef)#[test]fn test_zsh_wrapper_function_registered() {let repo = TestRepo::new();diff --git a/tests/snapshots/integration__integration_tests__init__init_bash.snap b/tests/snapshots/integration__integration_tests__init__init_bash.snapindex f45deb2c2..5ff5276c9 100644--- a/tests/snapshots/integration__integration_tests__init__init_bash.snap+++ b/tests/snapshots/integration__integration_tests__init__init_bash.snap@@ -165,8 +165,16 @@ wt_exec() {return $result}- # Completions are loaded from ~/.local/share/bash-completion/completions/wt- # Install with: wt config shell install+ # 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+ eval "$(COMPLETE=bash "$_WORKTRUNK_CMD" 2>/dev/null)" || return+ fi+ _clap_complete_wt "$@"+ }++ complete -o nospace -o bashdefault -F _wt_lazy_complete wtfi----- stderr -----diff --git a/tests/snapshots/integration__integration_tests__init__init_zsh.snap b/tests/snapshots/integration__integration_tests__init__init_zsh.snapindex cfcdbf5eb..c493bc696 100644--- a/tests/snapshots/integration__integration_tests__init__init_zsh.snap+++ b/tests/snapshots/integration__integration_tests__init__init_zsh.snap@@ -165,25 +165,22 @@ wt_exec() {return $result}- # Lazy completions via compdef - no fpath setup needed- # Regenerates on first TAB in each shell session- if (( $+functions[compdef] )); then- _wt_lazy_complete() {- # Load dynamic completion script once- unfunction _wt_lazy_complete 2>/dev/null || true-- # Generate & eval the real completer from the binary- local _script- _script="$(COMPLETE=zsh "$_WORKTRUNK_CMD" 2>/dev/null)" || return- eval "$_script"-- # Delegate to clap's generated function- if (( $+functions[_clap_dynamic_completer_wt] )); then- _clap_dynamic_completer_wt "$@"- fi- }+ # Lazy completions - generate on first TAB, then delegate to clap's completer+ # NOTE: This must come AFTER compinit in your .zshrc+ _wt_lazy_complete() {+ # Generate completions function once (check if clap's function exists)+ if ! (( $+functions[_clap_dynamic_completer_wt] )); then+ eval "$(COMPLETE=zsh "$_WORKTRUNK_CMD" 2>/dev/null)" || return+ fi+ _clap_dynamic_completer_wt "$@"+ }+ # Register completion (requires compinit to have run first)+ if (( $+functions[compdef] )); thencompdef _wt_lazy_complete wt+ else+ echo "wt: completions disabled (compinit not loaded yet)" >&2+ echo "wt: move 'eval \"\$(wt config shell init zsh)\"' after compinit in your .zshrc" >&2fifi