Autocomplete quick reference

Wordlist

Provide your own complete options. Useful for menu items that don't change.

complete -W "now tomorrow never" echo

Directory

Look for direcotries assuming a relative path.

complete -A directory echo

File

Look for files assuming a relative path.

complete -A file echo

Dynamic (ish)

Use a function to generate list of autocomplete values.

_echo_completions() {
    COMPREPLY+=("appeal")
    COMPREPLY+=("appear")
    COMPREPLY+=("append")
    COMPREPLY+=("apple")
    COMPREPLY+=("apply")
    COMPREPLY+=("bend")
}
complete -F _echo_completions echo
        

Dynamic

Autocalculate completions and filter using what's typed.

_echo_completions() {
    COMPREPLY=($(compgen -W "appeal appear append apple apply bend" "${COMP_WORDS[1]}"))
}
complete -F _echo_completions echo
        

Troubleshoot

Write environment variables to a file and tail the file from another terminal.

_echo_completions() {
    env > tmpfile
    COMPREPLY=($(compgen -W "appeal appear append apple apply bend" "${COMP_WORDS[1]}"))
}
complete -F _echo_completions echo