Skip to main content
Added reference for copied code
Source Link
terdon
  • 252.7k
  • 69
  • 481
  • 719

compgen will work only with one word, like the following :

compgen -c git 

Here is a custom solution for your case :

You will have first to source bash-completion script, then set the COMP_* vars so they meet this use case and then trigger programmatically the completion with the native bash_completion function xfunc and the results will then be gathered in COMPREPLY array (example taken from here):

# 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[@]}" 

P.S : To know the exact functions called during a command completion : use complete -p <command>

Output :

checkout cherry cherry-pick clean clone column commit config credential 

For a full overview of this, you can visit the owner post here

compgen will work only with one word, like the following :

compgen -c git 

Here is a custom solution for your case :

You will have first to source bash-completion script, then set the COMP_* vars so they meet this use case and then trigger programmatically the completion with the native bash_completion function xfunc and the results will then be gathered in COMPREPLY array :

# 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[@]}" 

P.S : To know the exact functions called during a command completion : use complete -p <command>

Output :

checkout cherry cherry-pick clean clone column commit config credential 

For a full overview of this, you can visit the owner post here

compgen will work only with one word, like the following :

compgen -c git 

Here is a custom solution for your case :

You will have first to source bash-completion script, then set the COMP_* vars so they meet this use case and then trigger programmatically the completion with the native bash_completion function xfunc and the results will then be gathered in COMPREPLY array (example taken from here):

# 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[@]}" 

P.S : To know the exact functions called during a command completion : use complete -p <command>

Output :

checkout cherry cherry-pick clean clone column commit config credential 

For a full overview of this, you can visit the owner post here

added 163 characters in body; edited body
Source Link
Reda Salih
  • 1.8k
  • 7
  • 9

compgen will work only with one word, like the following :

compgen -c git 

Here is a custom solution for your case :

You will have first to source bash-completion script, then set the COMP_* vars so they meet this use case and then trigger programmatically the completion with the native bash_completion function xfunc and the results will then be gathered in COMPREPLY array :

# 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[@]}" 

P.S : To know the exact functions called during a command completion : use complete -p <command>

Output :

checkout cherry cherry-pick clean clone column commit config credential 

For a full overview of this, you can visit the owner post here

compgen will work only with one word, like the following :

compgen -c git 

Here is a custom solution for your case :

You will have first to source bash-completion script, then set the COMP_* vars so they meet this use case and then trigger programmatically the completion with the native bash_completion function xfunc and the results will then be gathered in COMPREPLY array :

# 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[@]}" 

P.S : To know the exact functions called during a command completion : use complete -p <command>

Output :

checkout cherry cherry-pick clean clone column commit config credential 

compgen will work only with one word, like the following :

compgen -c git 

Here is a custom solution for your case :

You will have first to source bash-completion script, then set the COMP_* vars so they meet this use case and then trigger programmatically the completion with the native bash_completion function xfunc and the results will then be gathered in COMPREPLY array :

# 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[@]}" 

P.S : To know the exact functions called during a command completion : use complete -p <command>

Output :

checkout cherry cherry-pick clean clone column commit config credential 

For a full overview of this, you can visit the owner post here

added 104 characters in body
Source Link
Reda Salih
  • 1.8k
  • 7
  • 9

compgen will work only with one word, like the following :

compgen -c git 

Here is a custom solution for your case :

You will have first to source bash-completion script, then set the COMP_* vars so they meet this use case and then trigger programmatically the completion with the native bash_completion function xfunc and the results will then be gathered in COMPREPLY array :

# 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[@]}" 

P.S : To know the exact functions called during a command completion : use complete -p <command>

Output :

checkout cherry cherry-pick clean clone column commit config credential 

compgen will work only with one word, like the following :

compgen -c git 

Here is a custom solution for your case :

You will have first to source bash-completion script, then set the COMP_* vars so they meet this use case and then trigger programmatically the completion with the native bash_completion function xfunc and the results will then be gathered in COMPREPLY array :

# 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 

compgen will work only with one word, like the following :

compgen -c git 

Here is a custom solution for your case :

You will have first to source bash-completion script, then set the COMP_* vars so they meet this use case and then trigger programmatically the completion with the native bash_completion function xfunc and the results will then be gathered in COMPREPLY array :

# 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[@]}" 

P.S : To know the exact functions called during a command completion : use complete -p <command>

Output :

checkout cherry cherry-pick clean clone column commit config credential 
added 274 characters in body
Source Link
Reda Salih
  • 1.8k
  • 7
  • 9
Loading
Source Link
Reda Salih
  • 1.8k
  • 7
  • 9
Loading