Skip to content

Implement out-of-the-box support for shell autocompletion (source code available!) #113

@skyzyx

Description

@skyzyx

I haven't looked closely at the internals recently, so I'd like to leave that part to you. But by exposing a model of the command structure in #106 (responding to #104), I was able to write some re-usable code that provides shell auto-completion for Bash and Zsh. (I haven't attempted Fish or Powershell yet, but it'd be awesome if someone who knows those shells better than I could contribute those bits).

Here is the code. MIT licensed. Please steal and adapt. https://gist.github.com/skyzyx/149caddbf0c949da58618cb03b08e4d9

After compiling down to a single binary (e.g., mycmd), I'm able to setup autocompletion thusly:

Bash:

complete -C mycmd mycmd

Zsh:

autoload -U +X bashcompinit && bashcompinit
complete -C mycmd mycmd

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions