Skip to content

Commit 8997744

Browse files
authored
feat(release): install shell completions on brew install (DX-5783) (#39)
* feat(release): install shell completions on brew install (DX-5783) The cargo-dist-generated homebrew formula installs the binary but not shell completions, so brew users got no tab-completion out of the box. The formula is generated upstream and copied verbatim into the tap each release, so it can't be hand-edited durably; cargo-dist's template also dumps any bundled files into pkgshare, where shells don't read them. Patch the generated formula in release-update-homebrew-tap to run `qn completions <shell>` at install time via generate_completions_from_executable. `qn completions` is a pure local generator (no key, no network), so it's safe during brew install. The patch is idempotent and hard-fails if cargo-dist's install_binary_aliases! anchor disappears, so a template change can't silently drop completions. * docs(readme): note brew installs completions automatically (DX-5783)
1 parent 9696631 commit 8997744

2 files changed

Lines changed: 37 additions & 0 deletions

File tree

Justfile

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,13 @@ release-cargo-publish:
4949
# "homebrew" to publish-jobs in dist-workspace.toml, the cargo-dist
5050
# workflow takes over, and this recipe becomes a manual-recovery fallback.
5151
#
52+
# cargo-dist's homebrew template installs the binary but doesn't wire up
53+
# shell completions, so this recipe patches the generated formula to run
54+
# `qn completions <shell>` at install time. The patch is idempotent and
55+
# hard-fails if cargo-dist's install-method anchor goes missing — if you
56+
# hit that error, the template changed and the patch below needs updating.
57+
# When homebrew publishing is automated in CI, this patch moves with it.
58+
#
5259
# Usage: just release-update-homebrew-tap 0.1.0 ~/qn/homebrew-tap
5360
#
5461
# Precondition: tap_path is a clean local clone of quicknode/homebrew-tap
@@ -78,6 +85,30 @@ release-update-homebrew-tap version tap_path:
7885
mkdir -p Formula
7986
cp /tmp/qn.rb Formula/qn.rb
8087
rm /tmp/qn.rb
88+
# Wire up shell completions: cargo-dist's formula installs the binary but
89+
# not completions. `qn completions <shell>` is a pure local generator (no
90+
# key, no network), so it's safe to run during `brew install`. Insert the
91+
# helper after the `install_binary_aliases!` anchor in the generated
92+
# install method. Idempotent (skip if already present); fail loud if the
93+
# anchor is gone so a cargo-dist template change can't silently drop it.
94+
if ! grep -q 'generate_completions_from_executable' Formula/qn.rb; then
95+
if ! grep -q '^[[:space:]]*install_binary_aliases!$' Formula/qn.rb; then
96+
echo "Error: 'install_binary_aliases!' anchor not found in generated qn.rb." >&2
97+
echo "cargo-dist's formula template may have changed; the completions" >&2
98+
echo "patch in release-update-homebrew-tap needs updating." >&2
99+
exit 1
100+
fi
101+
awk '
102+
{ print }
103+
/^[[:space:]]*install_binary_aliases!$/ {
104+
match($0, /^[[:space:]]*/)
105+
indent = substr($0, 1, RLENGTH)
106+
print ""
107+
print indent "generate_completions_from_executable(bin/\"qn\", \"completions\")"
108+
}
109+
' Formula/qn.rb > Formula/qn.rb.tmp
110+
mv Formula/qn.rb.tmp Formula/qn.rb
111+
fi
81112
git add Formula/qn.rb
82113
if git diff --cached --quiet; then
83114
echo "Formula/qn.rb is already at v{{version}} on main. Nothing to do."

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ Pick the recommended path for your platform. Other channels are listed under [Al
3737
brew install quicknode/tap/qn
3838
```
3939

40+
Homebrew installs shell completions automatically — open a new shell after
41+
install (zsh users may need one `compinit` refresh) and `qn <TAB>` works.
42+
4043
### Scoop (Windows)
4144

4245
```powershell
@@ -242,6 +245,9 @@ qn team list
242245

243246
## Shell completions
244247

248+
Homebrew installs completions automatically (see above). For other install
249+
methods, generate them yourself:
250+
245251
```sh
246252
qn completions zsh > ~/.zfunc/_qn # zsh
247253
qn completions bash > /etc/bash_completion.d/qn # bash

0 commit comments

Comments
 (0)