Accessing bash completions for specific commands programmatically
I don't really know how it works, but the awesome window manager uses the following Lua code for getting access to bash completion's result:
https://github.com/awesomeWM/awesome/blob/master/lib/awful/completion.lua#L119
- Via
complete -p
we findcomplete -o bashdefault -o default -o nospace -F _git git
. We remember "_git" for later. - The length of "git l" is 5, so we set COMP_COUNT=6. We are completing the first argument to "git", so COMP_CWORD=1.
All together we use the following script:
__print_completions() { printf '%s\n' "${COMPREPLY[@]}"}# load bash-completion functionssource /etc/bash_completion# load git's completion function_completion_loader gitCOMP_WORDS=(git l)COMP_LINE='git l'COMP_POINT=6COMP_CWORD=1_git__print_completions
Output: "log"
Check in the /etc/bash_completion.d/
directory. This is where the different command completion scripts stay.
Quite an old question, but in the mean time I've implemented a script that handles this to reuse completions with ZSH