Repository navigation
Add generate completions to auto-generate extern definitions, with completions, from carapace, zsh, fish, man pages and --help - #19314
Merged
Conversation
…tions, from completion specs, man pages and `--help`
This was referenced Nov 13, 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.
Description
Nushell checks a call to an internal command before it runs, but an external command only gets that once someone writes an
externfor it, flag by flag, and completions only once someone writes a completer for it. Other tools already describe thousands of commands: carapace specs, fish and zsh completion files, man pages, and each command's--help.generate completions <command>reads one of them and returns the text of a module ofexport externdefinitions, with completer commands.You save that text and
useorsourceit, or save it in an autoload dir. Foruse, the file needs a name other than the tool's, such asgit-completions.nu, becauseusenames the module after the file and a module can't export an extern with its own name.carapace <tool> export), fish and zsh give the whole subcommand tree. man and--helpgive the flags of the named command, sogenerate completions "git status"readsman git-statusorgit status --help.--source, the first source that knows any flags wins, in the order carapace, fish, zsh, man, help.--source allmerges every source that knows any flags. When sources disagree, the earlier source wins. A flag they disagree on taking a value becomes a switch, and a flag any source says takes an optional value is left undeclared.--sourcenames, as in^git status -h | generate completions "git status" --source help.--color[=when]) or single-dash long options (-name). Those are listed in each extern's extra description, and they still reach the tool.With
@complete external, an external completer like carapace also lists the flags the signature declares, so flag completion showed each of them twice. Flag-name completion now drops command-wide suggestions that repeat a declared flag.User-facing changes (Release notes)
Generate external command definitions and completions
The new
generate completionscommand generates a module ofexterndefinitions and completers from carapace specs, fish or zsh completions, man pages, or--helptext. Save the output and load it withuseorsource, or place it in an autoload directory:When using
use, choose a filename other than the tool's name, such asgit-completions.nu. Generated modules provide flag-value and argument completions where the source supports them, including fixed lists, git branches, remotes and tags from fish completers, users and hosts, and native completions from Cobra-based tools such as gh, docker and kubectl.By default, the first source that knows any flags is used, in the order carapace, fish, zsh, man, then help. Use
--source allto merge sources. Carapace, fish and zsh provide subcommand trees; man and help provide flags for the named command. You can also pipe source text, as in^git status -h | generate completions "git status" --source help.Flag-name completion also no longer lists a flag twice when an extern with
@complete externaldeclares it and the external completer suggests it too.Additional notes
nu-check --as-module. So does every module from each source for git, ssh, make, rg, gh, tar, brew, curl, cargo, kubectl and docker, and from--source all.generate completionsrefuses a command named like a nushell keyword (fish ships completions forif,source,while), since an extern can't have that name._parse_helpon--help, which the help source already reads, and PowerShell's completers for native commands are script blocks registered at runtime.<command> --helpwith no input, the man source runsmanwithMANPAGER=cat, and a tool with acompletionsubcommand is asked<tool> __complete ""to find out whether it's built with cobra.