Skip to content

worktrunk: bind lazy dynamic completer for branch names - #493

Merged
bendrucker merged 1 commit into
mainfrom
worktrunk-fix-completions
Jun 17, 2026
Merged

bendrucker merged 1 commit into
mainfrom
worktrunk-fix-completions

Conversation

@bendrucker

Copy link
Copy Markdown
Owner

Makes wt switch <TAB> complete branch and worktree names. It only offered subcommands and flags before.

Three places tried to bind wt's completer and the dynamic one never won:

  • Homebrew autoloads a static _wt from fpath at compinit (subcommands and flags only).
  • completion.zsh eval'd wt config shell completions zsh, which on the installed 0.58.0 binary is that same static completer, and its trailing compdef _wt wt re-bound it. Redundant with the Homebrew autoload.
  • init.zsh defines _wt_lazy_complete, which delegates to clap's dynamic COMPLETE=zsh wt completer (already dynamic on 0.58.0). But init.zsh is sourced before compinit, so its compdef is guarded behind (( $+functions[compdef] )) and silently skipped.

So wt stayed bound to the static completer.

completion.zsh now binds _wt_lazy_complete itself, guarded by (( $+functions[_wt_lazy_complete] )), with the display zstyles from the init template. Because completion.zsh runs after compinit (in the deferred precmd hook), this binding wins over Homebrew's static one, and it drops the redundant static eval. init.zsh is unchanged: its wt() wrapper and _wt_lazy_complete definition are still needed, and its pre-compinit compdef is a harmless no-op.

This stays correct after a future brew upgrade makes the static command dynamic, since we no longer eval it. The binding rides on COMPLETE=zsh wt, which is the dynamic runtime path in both current and future binaries. (Worktrunk is also making wt config shell completions zsh dynamic upstream in a separate change.)

Testing

Launched a real interactive zsh loading this worktree's config (ZDOTDIR + DOTFILES_USE_DEV). wt switch <TAB> listed branch and worktree names with recency markers on the first TAB. ${_comps[wt]} then read _clap_dynamic_completer_wt, confirming the chain: _wt_lazy_complete bootstrapped on first TAB, eval'd COMPLETE=zsh wt, and handed off to clap's dynamic completer.

completion.zsh eval'd `wt config shell completions zsh`, which on the installed binary emits a static completer (subcommands and flags only), so `wt switch <TAB>` never offered branch or worktree names.

init.zsh defines _wt_lazy_complete (which delegates to clap's dynamic COMPLETE=zsh completer) but runs before compinit, so its compdef binding is silently skipped. Bind it from completion.zsh instead, which runs after compinit, along with the display zstyles. This also drops the redundant static binding that duplicated Homebrew's autoloaded _wt.
@bendrucker
bendrucker enabled auto-merge (squash) June 17, 2026 16:49
@bendrucker
bendrucker merged commit 3a1a303 into main Jun 17, 2026
6 checks passed
@bendrucker
bendrucker deleted the worktrunk-fix-completions branch June 17, 2026 16:54
bendrucker added a commit that referenced this pull request Jun 19, 2026
worktrunk 0.60.0 ships the upstream fix from worktrunk/worktrunk#3105: `wt config shell completions zsh` now emits a dynamic registration (the clap_complete::env path) that completes branch and worktree names, plus the recency-ordering zstyles, instead of a static subcommands-and-flags completer.

That removes the reason for #493's workaround, which bound init.zsh's _wt_lazy_complete by hand after compinit. Revert to the documented one-liner; the eval now runs after compinit (deferred completion hook), so its compdef binding takes effect.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant