compgen will work only with one word, like the following :
compgen -c git Here is a custom solution fir your case:
# load bash-completion helper functions source /usr/share/bash-completion/bash_completion # array of words in command line COMP_WORDS=(git c) # index of the word containing cursor position COMP_CWORD=1 # command line COMP_LINE='git c' # index of cursor position COMP_POINT=${#COMP_LINE} # execute completion function _xfunc git _git # print completions to stdout printf '%s\n' "${COMPREPLY[@]}" Output :
checkout cherry cherry-pick clean clone column commit config credential