Repository navigation
feat(completions): ship dynamic registration for package installs - #3105
Conversation
|
Looking into the test fail |
`wt config shell completions <shell>` emitted static clap_complete output (subcommands and flags only). Package installs (Homebrew) use this path, so `wt switch <TAB>` never completed branch or worktree names without first running `wt config shell install`. Emit a dynamic registration instead, reusing clap_complete::env for bash, zsh, fish, and powershell -- the same script `COMPLETE=<shell> wt` prints, which calls the binary at TAB time. Branch and worktree completion (already implemented via the dynamic completers) now works from a plain package install. Nushell already emitted its full dynamic template and is unchanged. Zsh needs a thin transform (make_zsh_autoload_safe) so the script works when autoloaded from fpath as site-functions/_wt: clap's trailing `compdef` is replaced with a dual-mode guard that completes directly when autoloaded and registers via compdef when sourced. The display zstyles precede the completer so single-column listing applies on the first TAB. The other shells need no transform: Homebrew sources bash files, autoloads fish completion files by command name, and powershell registrations are sourced into the profile. Also drop a dead `sed` hack from templates/zsh.zsh: clap emits `_describe -V` natively, so the substitution matched nothing. The homebrew-core `worktrunk` formula already calls generate_completions_from_executable(bin/"wt", "config", "shell", "completions"), which writes the bash, zsh, and fish output to the shells' default completion directories. So this change flows through on the next release/bottle build with no formula edit. Homebrew does not install powershell completions; that shell is switched for consistency and applies when sourced.
df82d57 to
a562a74
Compare
|
thank you very much @bendrucker ! so I understand: does this only change behavior for those who install with brew and don't install the shell integration? (or @worktrunk-bot feel free to opine) |
|
Yes — that's the right framing. The behavioral change lands on exactly one population: users who get Walking the three things this PR touches:
One nuance worth stating: it's not strictly "brew users." It's anyone whose install pipeline runs Net: strict improvement for the package-install-only crowd (they gain branch completion), no-op for everyone who ran |
| r#"# Single-column display keeps descriptions visually associated with each branch. | ||
| zstyle ':completion:*:{cmd_name}:*' list-max 1 | ||
| # Prevent grouping branches with identical descriptions (same timestamp) on one line. | ||
| zstyle ':completion:*:*:{cmd_name}:*' list-grouped false |
There was a problem hiding this comment.
Not necessary for completion to work — branches complete fine without them. They're a display-parity measure, copied verbatim from templates/zsh.zsh:86,89 so a package-install user sees the same listing as someone who ran wt config shell install.
What each does:
list-max 1— forces single-column. Without it zsh's default packs candidates into multiple columns.list-grouped false— stops zsh collapsing branches that share a description onto one line. Branch descriptions encode recency (-- + 12m), so several branches last touched ~12m ago would otherwise render grouped asrelease main -- + 12minstead of one branch per line. (That's the exact case the template comment atzsh.zsh:88calls out.)
So: drop them and completion still functions, but the listing regresses to multi-column + grouped, diverging from the install path.
One maintenance note while we're here: these zstyles now live in two places — templates/zsh.zsh and this hardcoded string in make_zsh_autoload_safe. test_completions_for_all_shells pins their presence and that they precede the guard, but not that they stay identical to the template, so the two could drift. Minor, but worth a comment cross-referencing the template if we want to keep them locked together.
|
ok, great! it seems like a nice improvement + some simplification, even if most folks have the shell integration installed? |
Release v0.60.0 (minor bump from 0.59.0). Minor because semver-checks flagged a breaking library-API change and five new features landed since v0.59.0. The data-loss surface review (4 independent finders) cleared the one change that touches it (relocating dirty linked worktrees, #3104). ### Improved - Package installs now complete branch/worktree names via dynamic registration (#3105, thanks @bendrucker) - `wt step relocate` moves dirty linked worktrees (#3104, thanks @lunaynx for reporting) - `--dry-run` previews print to stdout (#3085) - Picker gutter distinguishes local (`/`) and remote (`|`) branches (#3115) - `wt list --format=json` gains structured `repo`/`ci.repo` metadata (#3021, thanks @jeremy0dell) - `wt step eval --format=json` (#3106) - `--format=claude-code` rejected on `wt list` / `wt config state get` (#3116) ### Fixed - `cargo install worktrunk` builds from crates.io again (#3124, fixes #3123, thanks @kerrickstaley for reporting) - Tab-completion works in repos with no commits (#3097, closes #3094) - `wt config state get ci-status --format=json` honors `[forge].platform` (#3120) ### Documentation - `wt list --help` example tables fit the terminal (#3125) - `/wt-switch-create` cross-repo handling reworked (#3118) - Help-text and web-doc refinements (#3096, #3108, #3110, #3112, #3126) Full notes in `CHANGELOG.md`. > _This was written by Claude Code on behalf of max_
|
Yep, I of course have the shell integration installed but found the dynamic completions were clobbered by the presence of the static ones from Homebrew. |
ah!! that seems bad indeed... are you on zsh? I wonder if it's some ordering thing there. regardless: now fixed! |
|
Yes, zsh, and yes related to ordering. |
worktrunk 0.60.0 Created-by: HarmonybrewBot Commit-by: HarmonybrewBot Merged-by: HarmonybrewBot Description: Created by `brew bump` --- Created with `brew bump-formula-pr`.<details> <summary>release notes</summary> <pre>## Release Notes ### Improved - **Package installs complete branch and worktree names**: A plain `brew install worktrunk` (or other package install) now tab-completes branch and worktree names, not just subcommands and flags. `wt config shell completions <shell>` emits a dynamic registration that calls the binary at completion time (the maintained `clap_complete::env` path), matching what `gh`, `rustup`, and `kubectl` ship. ([#3105](max-sixty/worktrunk#3105), thanks @bendrucker) - **`wt step relocate` moves dirty linked worktrees**: Relocating a linked worktree with uncommitted or untracked changes no longer skips it. `git worktree move` carries those files along, so the dirty-skip was a worktrunk policy rather than a git limitation. The main worktree still skips when dirty (without `--commit`), since its relocation falls back to `git checkout`, which refuses to switch over a dirty tree. ([#3104](max-sixty/worktrunk#3104), thanks @lunaynx for reporting) - **`--dry-run` previews print to stdout**: `wt hook <type>`, `wt step relocate`, `wt step prune`, `wt step copy-ignored`, and `wt config shell install`/`uninstall` now send their `--dry-run` preview to stdout (the command's answer) while narration stays on stderr. This matches `wt list`, `git clean -n`, and `terraform plan`, and keeps previews pageable and pipeable. (Breaking: scripts reading these previews from stderr should now read stdout) ([#3085](max-sixty/worktrunk#3085)) - **Picker gutter distinguishes local and remote branches**: With `--branches` and `--remotes`, the `wt switch` picker marks each row's kind in the gutter: `/` for a local branch without a worktree and `|` for a remote branch, alongside the existing `@`/`^`/`+` worktree glyphs. ([#3115](max-sixty/worktrunk#3115)) - **`wt list --format=json` gains structured `repo` metadata**: JSON output adds `repo` (the local checkout's primary remote) and `ci.repo` (the repository `ci.url` targets, which differs for fork PRs) objects carrying `host`/`owner`/`name`/`provider`; the existing `repo_url` and `ci.repo_url` strings remain. The provider honors the configured `[forge].platform` on hosts that can't be auto-detected. ([#3021](max-sixty/worktrunk#3021), thanks @jeremy0dell) - **`wt step eval --format=json`**: `wt step eval` gains a structured `{name, template, result}` JSON lane on stdout, the machine-readable analog of its `-v` view. Text mode is unchanged. ([#3106](max-sixty/worktrunk#3106)) - **`--format=claude-code` rejected where it never applied**: `wt list` and `wt config state get` accepted `--format=claude-code` silently and treated it as `table`; the value only ever meant anything on `wt list statusline`. Both now fail fast with `invalid value 'claude-code'`. (Breaking: `wt list --format=claude-code` and `wt config state get --format=claude-code` now error) ([#3116](max-sixty/worktrunk#3116)) ### Fixed - **`cargo install worktrunk` builds from crates.io**: Installing from crates.io failed to compile with `environment variable VERGEN_GIT_DESCRIBE not defined at compile time`, because the package archive has no `.git` for the build script to read. The version lookup now falls back to the cargo package version when git-describe is unavailable. ([#3124](max-sixty/worktrunk#3124), fixes [#3123](max-sixty/worktrunk#3123), thanks @kerrickstaley for reporting) - **Tab-completion works in repos with no commits**: `wt switch <TAB>` and `wt remove <TAB>` returned nothing on a fresh `git init` repo, because the unborn default branch has no entry under `refs/heads/`. Completion now also draws on worktree branches, so the unborn `main` (and any `wt switch --create` branch on an empty repo) completes. ([#3097](max-sixty/worktrunk#3097), closes [#3094](max-sixty/worktrunk#3094)) - **`wt config state get ci-status --format=json` honors `[forge].platform`**: On a self-hosted host the parser can't recognize (Gitea, Azure DevOps, GitHub Enterprise on a generic domain), this path reported `provider: "unknown"` while `wt list --format=json` reported the configured provider. All structured-output paths now route the `[forge].platform` override through one accessor, so they stay consistent. ([#3120](max-sixty/worktrunk#3120)) ### Documentation - **`wt list --help` example tables fit the terminal**: The captured `wt list` example tables in `--help` chop to terminal width with a dimmed ellipsis (matching real `wt list`) instead of word-wrapping and shearing their columns; hand-authored command examples still wrap. ([#3125](max-sixty/worktrunk#3125)) - **`/wt-switch-create` cross-repo handling reworked**: The Claude Code plugin command's skill reworks how it creates and enters a worktree in another repo, built around what the harness actually does (`EnterWorktree` re-roots within the current repo; a `cd` reaches another repo when it's in `additionalDirectories`). The procedure dropped from five steps to three. ([#3118](max-sixty/worktrunk#3118)) - **Help-text and docs refinements**: `--format` help renders its values inline (`[possible values: table, json]`) instead of an expanded block; `wt switch` and `wt step push` help got smaller clarifications; and web-doc terminal blocks no longer wrap command-only lines. ([#3096](max-sixty/worktrunk#3096), [#3108](max-sixty/worktrunk#3108), [#3110](max-sixty/worktrunk#3110), [#3112](max-sixty/worktrunk#3112), [#3126](max-sixty/worktrunk#3126)) ## Install worktrunk 0.60.0 ### Install prebuilt binaries via shell script ```sh curl --proto '=https' --tlsv1.2 -LsSf https://github.com/max-sixty/worktrunk/releases/download/v0.60.0/worktrunk-installer.sh | sh && wt config shell install ``` ### Install prebuilt binaries via powershell script ```sh powershell -ExecutionPolicy Bypass -c "irm https://github.com/max-sixty/worktrunk/releases/download/v0.60.0/worktrunk-installer.ps1 | iex"; git-wt config shell install ``` ### Install prebuilt binaries via Homebrew ```sh brew install worktrunk && wt config shell install ``` ## Download worktrunk 0.60.0 | File | Platform | Checksum | |--------|----------|----------| | [worktrunk-aarch64-apple-darwin.tar.xz](https://github.com/max-sixty/worktrunk/releases/download/v0.60.0/worktrunk-aarch64-apple-darwin.tar.xz) | Apple Silicon macOS | [checksum](https://github.com/max-sixty/worktrunk/releases/download/v0.60.0/worktrunk-aarch64-apple-darwin.tar.xz.sha256) | | [worktrunk-x86_64-apple-darwin.tar.xz](https://github.com/max-sixty/worktrunk/releases/download/v0.60.0/worktrunk-x86_64-apple-darwin.tar.xz) | Intel macOS | [checksum](https://github.com/max-sixty/worktrunk/releases/download/v0.60.0/worktrunk-x86_64-apple-darwin.tar.xz.sha256) | | [worktrunk-x86_64-pc-windows-msvc.zip](https://github.com/max-sixty/worktrunk/releases/download/v0.60.0/worktrunk-x86_64-pc-windows-msvc.zip) | x64 Windows | [checksum](https://github.com/max-sixty/worktrunk/releases/download/v0.60.0/worktrunk-x86_64-pc-windows-msvc.zip.sha256) | | [worktrunk-aarch64-unknown-linux-musl.tar.xz](https://github.com/max-sixty/worktrunk/releases/download/v0.60.0/worktrunk-aarch64-unknown-linux-musl.tar.xz) | ARM64 MUSL Linux | [checksum](https://github.com/max-sixty/worktrunk/releases/download/v0.60.0/worktrunk-aarch64-unknown-linux-musl.tar.xz.sha256) | | [worktrunk-x86_64-unknown-linux-musl.tar.xz](https://github.com/max-sixty/worktrunk/releases/download/v0.60.0/worktrunk-x86_64-unknown-linux-musl.tar.xz) | x64 MUSL Linux | [checksum](https://github.com/max-sixty/worktrunk/releases/download/v0.60.0/worktrunk-x86_64-unknown-linux-musl.tar.xz.sha256) | ### Install via Cargo ```sh cargo install worktrunk && wt config shell install ``` ### Install via Winget (Windows) ```sh winget install max-sixty.worktrunk && git-wt config shell install ``` ### Install via AUR (Arch Linux) ```sh paru worktrunk-bin && wt config shell install ``` </pre> <p>View the full release notes at <a href="https://github.com/max-sixty/worktrunk/releases/tag/v0.60.0">https://github.com/max-sixty/worktrunk/releases/tag/v0.60.0</a>.</p> </details> <hr> See merge request: Harmonybrew/homebrew-core!11933
A plain package install of
wtcannot complete branch or worktree names.I found that
wt config shell completions <shell>emits a staticclap_complete::generate()registration, and the homebrew-core formula bakes that intosite-functions/_wtat install time viagenerate_completions_from_executable. The 0.58.0 binary shows:That static
_wtis what every Homebrew user has autoloaded bycompinit. It completes subcommands and flags and has no mechanism to list branches.Proposed Fix
wt config shell completionsnow emits a dynamic registration, the same scriptCOMPLETE=<shell> wtalready prints, which calls the binary at TAB time. The binary has always supported dynamic completion at runtime. The package path was simply wired to the wrong clap API:clap_complete::generate()is the legacy static path, andclap_complete::envis the maintained dynamic one. After this change a plainbrew installcompletes branch and worktree names with zero config, matching whatgh,rustup,kubectl, anddockership via their packages.Changes
clap_complete::env. It reuses clap's maintained body rather than hand-rolling a completer. Nushell already emitted its full dynamic template, so it is unchanged.make_zsh_autoload_saferewrites clap's trailingcompdefinto a dual-mode guard. Homebrew installs the zsh script assite-functions/_wtand autoloads it fromfpath, where the file body itself runs as the completion function. The guard completes directly when autoloaded and falls back tocompdefwhen sourced. The display zstyles precede the guard so single-column listing applies on the first TAB.sedhack fromtemplates/zsh.zsh. clap emits_describe -Vnatively, so the substitution matched nothing.Completionshelp text, which falsely claimed "static / only commands and flags."Homebrew installs completions for bash, zsh, and fish. PowerShell is switched to dynamic for consistency, but no package manager installs its completions, so it applies only when a user sources it.
Why Not
wt config shell install?installdoes bind dynamic completion, but a package install never runs it and should not have to.installexists for cd-on-switch: its job is thewt()wrapper that letswt switchchange the shell's directory, and it does so by appending aneval "$(...)"line to~/.zshrcor~/.bashrc. Completion is incidental to it.It only makes sense for Homebrew to run the completions command, since it's a pure function, no side effects. Changing the user's shell config during install would be unexpected.
Testing
Tested real shells with the completer present only via
fpathautoload (no eval, no install):wt switch <TAB>lists branch names on the first TAB, single-column.COMPLETE=zsh … wt switch '') still lists branches with recency markers.Fish reuses the exact
COMPLETE=fish wtmechanism thatwt config shell installalready ships, so it is proven in-tree. The strengthenedtest_completions_for_all_shellspins the dynamic registration structure for every shell.Related
I hit this and worked around it locally by binding the dynamic completer by hand after
compinit(bendrucker/dotfiles#493).