Skip to content

feat: add shell completion for step aliases - #1641

Merged
max-sixty merged 3 commits into
mainfrom
alias-autocomplete
Mar 21, 2026
Merged

max-sixty merged 3 commits into
mainfrom
alias-autocomplete

Conversation

@max-sixty

Copy link
Copy Markdown
Owner

Aliases configured in user/project config now appear as completable subcommands when tab-completing wt step <TAB>. Previously, only built-in step commands (commit, push, rebase, etc.) appeared since aliases are dynamic — they're resolved at runtime via the external_subcommand catch-all, which clap's completion engine doesn't know about.

The fix injects alias names as synthetic clap subcommands in the completion-only command tree. Each alias subcommand includes --dry-run, --yes/-y, and --var flags matching the real alias flag parser. Aliases that shadow built-in step commands are skipped. Shells that support it (fish, zsh) show the alias template as help text.

This was written by Claude Code on behalf of @max-sixty

Aliases configured in user/project config now appear as completable
subcommands when tab-completing `wt step <TAB>`. Each alias subcommand
includes --dry-run, --yes, and --var flags. Aliases that shadow built-in
step commands are skipped to avoid duplicates.

Co-Authored-By: Claude <[email protected]>
max-sixty and others added 2 commits March 21, 2026 12:26
Cover the truncation path (>60 chars) and multi-byte char boundary
handling that codecov flagged as uncovered.

Co-Authored-By: Claude <[email protected]>
@max-sixty
max-sixty merged commit e43032f into main Mar 21, 2026
23 checks passed
@max-sixty
max-sixty deleted the alias-autocomplete branch March 21, 2026 20:16
max-sixty pushed a commit that referenced this pull request Oct 1, 2026
)

`wt <alias> --<Tab>` (and `wt step <alias> --<Tab>`) offered `--dry-run`
and `--var`, but neither does anything useful after an alias.
`AliasOptions::parse` rejects `--dry-run` with "`--dry-run` is no longer
supported; use `wt config alias dry-run <name>` instead" (unless the
template references `dry_run`), and passes `--var KEY=VALUE` through to
the alias as plain positional arguments. Completion was steering users
into an error or a flag that silently does nothing.

The flags come from `build_alias_completion_command` in
`src/completion.rs`, a stub that predates alias argument routing (added
in #1641; `--dry-run` was retired for aliases in #2291 and #2304). This
PR removes the stub's own `--dry-run`, `--yes` and `--var` declarations,
so the stub declares nothing beyond the alias name and help text.
Aliases that wrap a built-in (`co = "wt switch {{ args }}"`) still
mirror that built-in's flags through `mirror_alias_command`, which this
PR doesn't touch.

**Test:** `test_complete_step_alias_shows_flags`, which asserted the
stale flags were present, becomes
`test_complete_step_alias_offers_no_misleading_flags` and asserts
`--dry-run` and `--var` are absent. It fails on `main` (`Unexpected
--dry-run flag`) and passes with the fix. All 80 completion integration
tests pass.

**Not covered:** `--yes` still completes after an alias, and so do
`--config` and `--verbose`, because they are clap `global = true` flags
on the root command and propagate into every subcommand's completions.
After an alias they also forward as arguments (the alias parser tests
note that `global = true` doesn't cross `external_subcommand`). Removing
them would mean hiding globals per alias stub, which is a separate
decision. The stub's own `--yes` declaration duplicated the global, so
dropping it changes nothing.

Co-authored-by: worktrunk-bot <[email protected]>
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.

2 participants