_foobar()
{
    COMPREPLY=()
    COMP_WORDBREAKS=" "
    local cur=${COMP_WORDS[COMP_CWORD]}
    local cmd=(${COMP_WORDS[*]})

    # https://devmanual.gentoo.org/tasks-reference/completion/index.html
    local choices=$(${cmd[*]} --completions ${COMP_CWORD})
    COMPREPLY=($(compgen -W '${choices}' -- ${cur} ))

    return 0
}
complete -F _foobar foobar
