Repository navigation
worktrunk: bind lazy dynamic completer for branch names - #493
Merged
Merged
Conversation
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
enabled auto-merge (squash)
June 17, 2026 16:49
This was referenced Jun 17, 2026
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:_wtfromfpathatcompinit(subcommands and flags only).completion.zsheval'dwt config shell completions zsh, which on the installed 0.58.0 binary is that same static completer, and its trailingcompdef _wt wtre-bound it. Redundant with the Homebrew autoload.init.zshdefines_wt_lazy_complete, which delegates to clap's dynamicCOMPLETE=zsh wtcompleter (already dynamic on 0.58.0). Butinit.zshis sourced beforecompinit, so itscompdefis guarded behind(( $+functions[compdef] ))and silently skipped.So
wtstayed bound to the static completer.completion.zshnow binds_wt_lazy_completeitself, guarded by(( $+functions[_wt_lazy_complete] )), with the display zstyles from the init template. Becausecompletion.zshruns aftercompinit(in the deferred precmd hook), this binding wins over Homebrew's static one, and it drops the redundant static eval.init.zshis unchanged: itswt()wrapper and_wt_lazy_completedefinition are still needed, and its pre-compinitcompdefis 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 makingwt config shell completions zshdynamic 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_completebootstrapped on first TAB, eval'dCOMPLETE=zsh wt, and handed off to clap's dynamic completer.