r/zsh • u/tanaydin • 2h ago
I made a plugin that completes options for any command without a completion, by reading its --help
Every tool has its own flags, and I didn't want to remember them for each one, or open --help every time I needed one. zsh completes them for tools that ship a completion (git, docker, ...), but for my own scripts and newer CLIs, Tab on -- gave nothing or a list of files. So I wrote a small plugin that fills that gap:
https://github.com/tanaydin/zsh-help-complete
What it does
For any command that has no completion of its own, it reads the command's help and uses it for completion:
tool --<Tab>suggests the options; if nothing matches, you get normal file completion.tool <Tab>lists its subcommands with descriptions, andtool sub --<Tab>readstool sub --help.tool --env <Tab>offers the values the help lists: argparse{staging,production}, clap[possible values: ...], commander(choices: ...). Values namedDIRcomplete directories,FILEfiles.
It works for commands in PATH, ./script.py and aliases.
Why not just compdef _gnu_generic**?**
That was my first try. It works for a lot of tools, but I ran into a few problems:
- Some help output breaks it. A line like
--system-prompt[-file],makes_argumentsfail withinvalid option definition, or it silently hides the real--system-promptoption. The plugin drops those lines before parsing and keeps GNU style--color[=WHEN]. - It doesn't know that
--tag TAGtakes a value, so--tag v1 --<Tab>goes wrong. - A command that doesn't understand
--helpand waits for input freezes the shell. Here help runs with a timeout and with stdin closed. - It runs things without asking (more on that below).
Other details
- Commands with their own completion (git, docker, ...) keep it. The plugin only steps in when that completion finds nothing for an option word. For example, zsh 5.9's
_mvcan't completemv --backup --<Tab>, because it treats the next word as the backup type. - Results are cached in
~/.cache/zsh-help-completeand refreshed when the binary changes, so updating a tool doesn't needexec zsh. - Settings are zstyles: timeout, help flags per command, a denylist, ignore patterns, etc.
The obvious caveat: completing means running the program
--help is a convention, not a guarantee. A script that never looks at its arguments will just do its job when you Tab on ./cleanup.sh --. So:
- By default it asks before running a program for the first time, showing the full path:
run "mytool --help" (/usr/local/bin/mytool)? [y]es [o]nce [n]ot now ne[v]er. If the file changes after you allowed it, it asks again. Only option words ask;tool <Tab>for an unknown program just completes files and runs nothing. - Shell scripts with no sign of handling
--helparen't run at all, and shell scripts' subcommands are never run (so./manage.sh deploy --<Tab>can't trigger a deploy). - Only
--helpis tried by default (-hisn't help everywhere), andrm,dd,shutdownand friends are on a denylist. - Optionally,
zstyle ':zhc:*' sandbox yesruns the help call read-only and without network (bubblewrap on Linux,sandbox-execon macOS).
You can turn the question off (zstyle ':zhc:*' ask no) if you trust everything you complete.
Works with oh-my-zsh, zinit, antidote, or a plain source after compinit. Tested with zsh 5.9 on Linux and macOS. To try it:
git clone https://github.com/tanaydin/zsh-help-complete ~/.zsh/zsh-help-complete && echo 'source ~/.zsh/zsh-help-complete/zsh-help-complete.plugin.zsh' >> ~/.zshrcI'd love feedback, especially help formats it gets wrong, and whether the first-run question feels right or annoying.

