Skip to content

refactor(wt): parse the remaining bins with zarg - #84

Merged
radiosilence merged 1 commit into
mainfrom
feat/wt-zarg
Aug 7, 2026
Merged

refactor(wt): parse the remaining bins with zarg#84
radiosilence merged 1 commit into
mainfrom
feat/wt-zarg

Conversation

@radiosilence

Copy link
Copy Markdown
Owner

What this does

#82 moved wtclean to zarg and left the other four bins hand-rolled. This finishes the job: wt-list, wt-preview, wt-picker and wt-shell now declare their interface once and get the parser, --help and completions from it.

Registered in generate:completions:plugin — the by-path variant #82 added, since these live in plugins rather than on PATH and the usual command -v gate would skip them without saying so.

Why this and not #80

#80 should be closed. It did the same job by hand — a case statement per script emitting a literal #compdef heredoc — and invented its own by-path Taskfile entry, which would now duplicate generate:completions:plugin. zarg's whole premise is that a hand-written parser/compdef pair drifts the moment you add a flag, and #80 is four instances of exactly that pair. Superseded on both counts.

Load-bearing decisions

  • Branch arguments use complete=_wt_branches rather than a fresh worktree listing. That function already backs the wt and wtrm compdefs, so there's one place that knows how to enumerate worktrees for completion.
  • zarg is sourced before set -euo pipefail, not after. It exits the script itself on a parse error, so it doesn't need -e, and running it under -u risks tripping over its own optional-variable handling for no benefit.
  • wt-preview keeps the tab-stripping. fzf-tab passes the whole branch<TAB>path line as one word, so ${branch%%$'\t'*} still applies after zarg binds it.
  • ~1.5ms to source zarg, measured — irrelevant for wt-preview, which is already making a gh pr view call per render.

How to confirm

zsh-plugins/wt-core/bin/wt-list --help
zsh-plugins/wt-core/bin/wt-list --nope          # rc=2, did-you-mean
task generate:completions

Verified: all five emit completions that parse under zsh -n; compinit registers every one from a scratch fpath (wt-list -> _wt-list and so on); wt-list still lists and still resolves a single branch; wt-preview still previews; required positionals are enforced on wt-shell.

Not covered by testing

wt-picker and wt-shell past their argument handling — both need a TTY, and wt-picker with no arguments blocks on fzf by design.

🤖 Generated with Claude Code

https://claude.ai/code/session_01SdK2s5sJBVLc5Edhm3cZ3H

wtclean moved to zarg in #82 and the other four were left hand-rolled,
which is exactly the drift zarg exists to prevent. One declaration now
yields the parser, --help and completions for all five.

Branch arguments reuse _wt_branches, the function already backing the wt
and wtrm compdefs, rather than a second way to list worktrees.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SdK2s5sJBVLc5Edhm3cZ3H
@radiosilence
radiosilence merged commit c5a6dc2 into main Aug 7, 2026
2 checks passed
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