Does a tool exist that will automatically generate completion files for both bash and zsh?

I'd like to be able to specify one source of truth for my completions instead of maintaining a separate completion file for bash and zsh.


To complete short and long options and file names, make sure that the program generates a usage description with --help in the same format as GNU tools. Then set it up for completion with:

  • complete -F _longopt myprogram in bash
  • compdef _gnu_generic myprogram in zsh

If you want something more powerful, define bash completions and use zsh's bash compatibility mode. Users must call bashcompinit in their .zshrc, then they can call complete -F _myprogram_bash_complete myprogram in zsh as well as bash. Zsh only emulates a subset of bash, so test your completion function to ensure that it doesn't require features that zsh doesn't emulate.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.