Zsh completion basics

From wikinotes

Simple Example

# compdef backup_user                  # <-- program(s) to complete

_arguments \
  '1:firstname:_normal' \              # <-- positional param 1
  '2:file:_normal'                     # <-- positional param 2
  '3::foo:_normal'                    # <-- optional positional param 3 (2x ::)
  {-h,--help}'[show help]' \          # <-- flag param (no value)
  '-o[output file]::outfile:_files' \    # <-- flag param (with 'file' value)

Actions

Actions are used in params that require a followup value param.
They determine the types of completions that will be suggested.

There is a large variety of builtin functions like these:

# usage
_arguments \
  '1:name:_normal'

# some useful actions:
_normal      # complete a word
_parameters  # one or more normal args
_files        # complete filepaths
_user        # complete from OS users
_groups      # complete from OS groups

You can also provide an array of choices

_arguments \
  '1:name:(alex will maize)' \                                         # completion choices for positional arg
  {-c,--component}":component:(mail calendar contacts tasks memos)" \  # completion choices for keyword arg