shellautocompletezshtab-completionzsh-completion

How to list all zsh autocompletions?


In zsh, I'm trying to get an idea of which commands have an existing completion so that I can write completions for commands that don't.

Is there a way to list the commands that zsh will complete without grepping the completion files? For instance, is there a built-in command that will list them?


Solution

  • The list of known completions is stored in the associative array _comps. The command names and other completion contexts are used as keys for _comps, while the corresponding completion functions are stored as values.

    You can get a full list of commands with associated completions with the following command:

    for command completion in ${(kv)_comps:#-*(-|-,*)}
    do
        printf "%-32s %s\n" $command $completion
    done | sort
    

    Explanation: