Repository navigation
docs: add bash and zsh autocompletion recipe - #215
Merged
Merged
Conversation
draj256
approved these changes
Oct 16, 2026
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.
Summary
Closes #200 — adds a bash and zsh shell autocompletion recipe to
docs/reference/cli/README.md.docs/reference/cli/README.mddocumented everyranusubcommand and flag but had no autocompletion recipe, so macOS and Linux developers had to memorise flags or fall back toranu help.What was added
A new §5 Shell Autocompletion section containing:
compgen-based completion script, registered for bothranuand theranujsalias. Handles value-taking flags (--rootcompletes directories,--adaptercompletesvercel/@ranujs/adapter-vercel,--port/--hostcomplete nothing), per-subcommand flag sets, and a bare-offering only short flags._arguments/_describewidget with descriptions for every command and flag, plus a note thatcompinitmust run before the file is sourced (so it cannot live in~/.oh-my-zsh/completions).complete -p ranu/whence -w _ranuchecks a reader can run to confirm the script loaded, and the exact expected output of pressing Tab.bash-completion, or explicitly sourced), macOS systembash3.2 (which ships no completion loader, so it must be sourced from~/.bash_profile), and Homebrew bash.Flag sets are derived from the real CLI, not guessed
The repo does not use
commanderoryargs— it has a hand-rolled parser inpackages/cli/src/args.tsand per-command help text inpackages/cli/src/commands/help.ts. Each completion set mirrorsranu help <command>exactly:--help,--versiondev--root --port --host --clean --open --verbose --debug --quiet --json --help --versionbuild--root --clean --verbose --debug --quiet --json --help --versionstart--root --port --host --verbose --debug --quiet --json --help --versioncreate--root --verbose --debug --quiet --json --help --versiondeploy--root --adapter --verbose --debug --quiet --json --help --versionhelp/version--json --helpTwo details worth noting, both taken from source rather than assumption:
--host's shorthand is-h, not--help— an easy trap for a completion script to get wrong.--port,--host,--root,--adapterand--openare parsed globally, buthelp.tsdocuments--openonly fordevand--adapteronly fordeploy. The scripts follow the documented per-command surface rather than the parser's laxer global behaviour, so the suggestions match whatranu help <cmd>tells the user.ranu help <TAB>completes the seven subcommand names, matchingrunHelpCommand.Testing — both scripts were actually executed
Not just written; both were run against real completion systems:
COMP_WORDS/COMP_CWORDand calls_ranudirectly, assertingCOMPREPLYfor subcommand completion, prefix filtering (--p→--port,--por→--port,--poonbuild→ nothing), value-position behaviour,ranu help b→build, and flags after an already-typed--clean.zsh -f -iinside asocat-allocated pty.compinitruns,_ranuiscompdef'd, a literal Tab is sent, and the completions the real zsh completion system prints on screen are parsed and compared per subcommand.Both bugs the tests caught were fixed rather than papered over: the zsh widget originally offered the full flag set at root level and for
help/version, andbuildlost its--cleanduring a refactor. The scripts embedded in the README are byte-identical to the tested ones (verified by diffing the extracted code blocks).Both shells also pass syntax checks (
bash -n,zsh -n).Checks
node scripts/sync-docs-version.mjs --check→ passes.prettier --checkon the isolated section passes). Sections 1–4 of this file were already non-compliant onmain— I verified this on the stashed baseline — so I deliberately did not reformat them, which would have turned a 244-line additive docs change into an unrelated whole-file reformat.CONTRIBUTING.md.Left for the maintainer
@ranujs/coreship acompletions/directory consumed by a loader, that is a package-layout change and a different issue.--hostentry uses(-h --host), so-hexpands to--host. That matches the CLI, but if the project ever wants the conventional-h=--help, the CLI parser needs to change first.bash3.2 and Homebrew bash, but I had no macOS host to confirm against.