Skip to content

feat: wt <worktree> is short for wt cd <worktree> - #2

Merged
lorenzolfm merged 1 commit into
mainfrom
bare-worktree-shorthand
Aug 28, 2026
Merged

lorenzolfm merged 1 commit into
mainfrom
bare-worktree-shorthand

Conversation

@lorenzolfm

Copy link
Copy Markdown
Owner

wt cd <worktree> is verbose for the command you type most often, so an unknown first word is now a worktree name. It reaches the same lookup as wt cd, so a branch name and the start of a directory name work in the short form as well.

Collisions. A command wins over a worktree with the same name, because clap reads the first word as a command before anything else. wt ls therefore prints the worktrees also when a worktree has the name ls, and the long form wt cd ls reaches that worktree. Three things keep the rule visible:

  • wt add prints a warning when it makes a directory with the name of a command. The list of commands comes from clap itself, so it cannot drift.
  • A word that is neither gives one message for both: there is no command or worktree with the name snyc.
  • wt --help names the short form, and wt help cd gives the rule.

Shell. The fish function now names the commands that write for the user, and reads a path from every other word. The binary therefore decides what is a worktree. A worktree name also completes in the position of a command.

Tested in a throwaway repository: the short form, a branch name, a prefix, a worktree with the name ls, a mistyped command, and the fish function on each of them.

`wt cd <worktree>` is verbose for the command you type most often, so an
unknown first word is now a worktree name. Clap gives that word to an
external subcommand, and it reaches the same lookup as `wt cd`, so a branch
name and the start of a directory name work in the short form as well.

A command wins over a worktree with the same name, because clap reads the
first word as a command before anything else. `wt ls` therefore prints the
worktrees also when a worktree has the name ls, and the long form
`wt cd ls` reaches that worktree. `wt add` prints a warning when it makes a
directory with the name of a command. The list of commands comes from clap
itself, so it cannot drift. A word that is neither gives one message for
both, so a mistyped command does not read as a missing worktree.

The fish function now names the commands that write for the user, and reads
a path from every other word. The binary therefore decides what is a
worktree, and a worktree name completes in the position of a command.
@lorenzolfm
lorenzolfm merged commit 295e8a0 into main Aug 28, 2026
4 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