Open jnikula opened 3 years ago
I'm not sure if that's possible with argcomplete - git registers its own completion module that gets activated when bash sees a command line that starts with git
.
With that said, I have some custom git commands defined in my ~/.gitconfig, and the git completion module completes them for me.
To provide completions for git some-command
, git completion looks for a function called _git_some_command
.
If git-some-command
is written to be completed with argcomplete, you just need to define a wrapper function that
_python_argcomplete
like normal completion would.Using the example from argcomplete docs:
chmod +x describe_github_user.py
ln -s describe_github_user.py git-describe-github-user
PATH+=:$PWD
_git_describe_github_user() {
# replace command word and following spaces with `git-'
local new_line="git-${COMP_LINE##"${COMP_WORDS[0]}"+( )}"
# adjust point to account for the difference in line length
COMP_POINT=$(( COMP_POINT - ${#COMP_LINE} + ${#new_line} ))
COMP_LINE=$new_line
# call the argcomplete handler
_python_argcomplete "git-describe-github-user"
}
and now you'll get completions for git describe-github-user
as expected.
git
and some other tools support user-defined subcommands by havinggit-some-subcommand
inPATH
. Runninggit some-subcommand
runs the custom subcommand viagit
binary. I can't figure out how to make argcomplete support completion on that subcommand alone. Obviously it works forgit-some-subcommand
directly, but how to enable it viagit
while preserving regulargit
completion?