Command line completion

Command line (aka tab) completion is popular in the Unix world as it helps typing speed, prevents typos and makes the shell more user-friendly.

The problem

Impementing filename completion is easy. Implementing command-specific completion like git com<tab> is not.

Completion scripts are different across Bash, Zsh and Fish. Time consuming to implement and maintain, sometimes out of date, hacky in general. some examples

A modest proposal

Shellcomp is a simple standard to perform completion. Completion is implemented in the command about to be run: The shell runs the command with a specific --tabcomplete '<partial_string>' option. The command responds with simple JSON structure that the shell will parse to perform completion or display help messages.


The JSON format

The JSON document is to be printed to stdout; All fields are optional:

v version. completions a list of valid completion values with an optional help message. alt alternative completions: other commands that the user might want to use. help contextual help message.

An example response for “git con"

        "v": 1,
        "completions": [
            ["config", "get and set repository or global options"],
        "alt": [
            ["commit", "record changes to repository"]
        "help": "",

Fields usage:

How to implement it

In the long term, popular shells like Bash, Zsh, Fish could support the standard and consume the JSON document.

In the short term, a simple wrapper could run the application on behalf of the shell and perform “traditional” completion. This allows a progressive deployment.

Applications can implement completion internally or through helper libraries like DocOpt or Click

How to contribute