zsh completion

basic notes on zsh completion system

SEAN K.H. LIAO

zsh completion

basic notes on zsh completion system

completion

TAB all the way.

zsh

zsh manual

compinit

initialize the completion system

compinit -d ${XDG_CACHE_HOME:-$HOME}/.zcompdump
compdef

using a shell function generate completions

compdef function_to_use commands to complete

# when used as the first line of an autoloaded function found during compinit
#compdef ...

# reuse completions created for command2 for command1
compdef command1=command2
# ex:
alias tf=terraform
compdef tf=terraform

bash

use bash completion in zsh

bash manual

bashcompinit

call after compinit

bashcompinit
complete

how to complete commands

complete -o option -[CF] command

# commonly used to not add extra space
-o nospace

complete -C command_output_used_as_completion command
complete -F function_output_used_as_completion command