feat: install bash and zsh completions for gt#30
Open
sumanthratna wants to merge 1 commit into
Open
Conversation
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.
Install bash and zsh completions for gt
brew install withgraphite/tap/graphitecurrently installs no shell completions, even though the CLI ships agt completioncommand. This PR generates and installs them at install time using Homebrew's standardgenerate_completions_from_executablehelper.Staleness isn't a concern with this approach: the script yargs emits is a thin shim that invokes
gt --get-yargs-completions <words>live on every Tab press, so the installed file never goes out of date as gt's commands evolve — it only needs to be installed once.Supersedes #3
Credit to @jalaziz for the original attempt in #3. Investigating why that diff "didn't work as expected", I found two root causes, both fixed here:
feat: Generate shell completions on install #3 requested
:fish, which yargs cannot emit. gt is built on yargs, whosecompletioncommand only generates bash or zsh scripts, selected via theSHELLenvironment variable (whichgenerate_completions_from_executablesets per shell). UnderSHELL=fish, yargs falls back to emitting a bash script, which Homebrew then installed into fish's completions directory — a broken fish "completion" that fails the moment it's exercised. This PR explicitly passesshells: [:bash, :zsh](the helper's default list includes fish, so it must be overridden).The yargs zsh script only registers the completer. It ends with
compdef _gt_yargs_completions gtand never invokes the function (Generate zsh autoload completion function file yargs/yargs#2402; the#compdef gtheader came in Zsh completion is now installable system-wide yargs/yargs#1856). When zsh autoloads_gtfrom fpath on the first Tab of a session, the file runs, registers the completer, and returns — completing nothing on that first press. This PR appends a_gt_yargs_completions "$@"invocation to the installed_gtso the first Tab works.What the diff does
install_shell_completionshelper, called from each of the threedef installblocks, in the template (formula-templates/graphite.rb) and both rendered formulas (Formula/graphite.rb,Formula/graphite-beta.rb) so the release pipeline won't clobber the change on the next version bump.shell_parameter_format: :none— yargs keys on theSHELLenv var the helper sets; it would rejectgt completion bash.chmod 0555, bin/"gt"before generating — the downloaded release artifact carries no exec bit, and Homebrew normalizes permissions only afterinstallreturns, so without it the helper fails withbrew: exec failed (EACCES)(reproduced during testing).Per the discussion in #4, the diff is intentionally minimal — no unrelated audit cleanups, no changes to
version/test.Testing (macOS arm64, gt 1.8.6)
Installed the patched formula via a local tap (current Homebrew rejects
brew install --formula <path>); install succeeds and Homebrew reports the completions:Generated zsh script is the registration shim plus the appended invocation:
Bash variant landed in bash's dir (and is actually bash, not zsh):
No file was written into
share/fish/vendor_completions.d/(fish correctly excluded).A clean zsh registers the completer:
The live query the shim performs on each Tab returns the subcommand list:
And interactively,
gt <Tab>completes on the first press of a fresh shell session (the failure mode from root cause 2).brew stylereports no offenses for the added lines (the one pre-existingComponentsOrderwarning is untouched, keeping this PR minimal).Question for maintainers
This repo's
src/index.tsrenders the template intoFormula/graphite-beta.rbonly, and stable promotion appears to happen via a separate mechanism. If that pipeline rendersFormula/graphite.rbfrom a template copy living outside this repo, that copy needs the same change or the next stable release will revert it — happy to adjust whatever is needed.