1

I've been trying to add an autocomplete for my custom command, "git extract-unmerged". I'm using git on Windows in git bash through MSYS2 if it matters.

I created a bash script in $HOME/bash_completion.d/git-extract-unmerged.bash which is correctly included to env on shell startup.

It works well for a command arguments after I type "git extract-unmerged <TAB>", but I would like to have autocompletion working if I also type just "git extr<TAB>" and would expect that shell would return "git extract-unmerged ", like it does for built-in git commands.

Is this possible for custom git commands?

I have a hunch that autocompletion of commands is built-in into git.exe and that without modifying the source and recompiling, it is not possible...

0

1 Answer 1

0

So I found one possible solution - define git alias as an alias to itself, i.e. for this case:

git config --global alias.extract-unmerged extract-unmerged

The reason why it works is because in "git-completion.bash", in __git_main(), it will search and compare currently written git command before <TAB>, i.e. "extr" with the output of:

git --list-cmds=list-mainporcelain,others,nohelpers,alias,list-complete,config

So if a command is aliased with itself, it will be included in the list, alias will be replaced with the whole command (in this case 1-to-1 replacement), and command autocompleted.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.