refactor(wt): move wtclean's logic into the script - #85
Merged
Conversation
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
The plugin defined _wt_clean, _wt_pr_cache and _wt_fan, and bin/wtclean
was their only caller — every interactive shell parsed ~150 lines it
would never run. Worse, zarg parsed --dry-run into $dry_run and the
script re-encoded it back into -n so the function could parse it again,
with a comment explaining the gotcha that round trip created.
The genuinely shared helpers (_wt_root, _wt_base, _wt_named,
_wt_pr_state) stay in the plugin, where wtrm and the picker use them.
_wt_prs keeps its declaration next to _wt_pr_state rather than moving
with the code that fills it: an undeclared associative array makes
${_wt_prs[feat/x]} an arithmetic subscript, so "feat/x" is evaluated as
a division and any slashed branch name dies with "division by zero".
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SdK2s5sJBVLc5Edhm3cZ3H
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SdK2s5sJBVLc5Edhm3cZ3H
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.
What this does
_wt_clean,_wt_pr_cacheand_wt_fanlived in the plugin withbin/wtcleanas their only caller — about 150 lines that every interactive shell parsed and never ran. They move into the script. Only the helpers something else actually shares stay behind:_wt_root,_wt_base,_wt_named,_wt_pr_state, used bywtrm,_wt_coreand_wt_branches.Why
The split forced arguments through a round trip. zarg parsed
--dry-runinto$dry_run, then the script re-encoded it so a function could parse it a second time:That comment documents a gotcha which only exists because of the file boundary. With the body in the script it reads
$dry_rundirectly and both the array and the comment disappear.The justification in the old header — "the logic lives in the plugin next door so wtrm can share
_wt_pr_state" — didn't hold up._wt_pr_statestays in the plugin either way; that was never an argument for the body being there.The one thing that had to stay put
_wt_prskeeps itstypeset -gAbeside_wt_pr_state, not with_wt_pr_cachewhich fills it. Moving it brokewtrmfor every branch with a slash in the name:An undeclared associative array makes
${_wt_prs[feat/x]}an arithmetic subscript, so zsh evaluatesfeat/xas a division of two unset variables. Silent for flat branch names, fatal forfeat/…. Found by testingwtrm's path after the move, not by reading the diff.How to confirm
wtclean -n wtclean --dyr-run # rc=2Verified: identical output through the script and through the plugin shim; unknown flags still refused by zarg; and
_wt_pr_stateresolvesfeat/wt-zarg,feat/linux-bootstrapand flat names correctly with only the plugin loaded, which is the pathwtrmtakes.Merged
mainin to pick up #83.🤖 Generated with Claude Code
https://claude.ai/code/session_01SdK2s5sJBVLc5Edhm3cZ3H