2

I have configured my .bash_aliases like:

alias gc="git checkout"
alias gcf="git flow feature checkout"
source ~/.git-completion.bash
__git_complete gc  _git_checkout
source ~/.git-flow-completion.bash
__git_complete gcf __git_flow_feature

But when I try to complete I should select checkout and then I may select my branch:

$ gcf 
checkout   diff       help       publish    rebase     track      
delete     finish     list       pull       start      

$ gcf checkout a
a_branch1 a_branch2

What should I do that checkout will be selected automatically when I write gcf+aTAB

Eugen Konkov
  • 15,716
  • 7
  • 69
  • 107

1 Answers1

3

I think one solution might lie with custom Git alias completion:

If you use complex aliases of form !f() { ... }; f, you can use the null command : as the first command in the function body to declare the desired completion style. For example !f() { : git commit ; ... }; f will tell the completion to use commit completion. This also works with aliases of form !sh -c '...'. For example, !sh -c ': git commit ; ... '.

So you'll first need to set up a Git alias in your .gitconfig:

[alias]
  ffc = "!ffc() { : git checkout ; git flow feature checkout $@ ; } && ffc"

and then link it in .bash_aliases:

alias gcf="git ffc"

It's untested but I think it'll do what you want. You might have some trouble with spacing in the $@ in the ffc alias that \"$@\" might fix depending on use case.

Pockets
  • 1,068
  • 7
  • 12
  • Whoops, forgot to mention [this](https://github.com/git/git/blob/master/contrib/completion/git-completion.bash#L20-L24) - I think this only works after you source `git-completion.bash`, which is probably best to do in your `bashrc`. LMK if that fixes it for you and if it does I'll edit the answer with it. – Pockets Nov 30 '16 at 19:44
  • As I have mention in my question: `source ~/.git-completion.bash` is aready in by `~/.bashrc`. I need something like `__git_complete gcf __git_flow_feature_XXXXX`. and I can not find `XXXXX` – Eugen Konkov Dec 01 '16 at 08:32
  • although your answer do not resolve my problem I reward you for your try ;-) – Eugen Konkov Dec 01 '16 at 14:39
  • Huh. In that case I'm not really sure how to fix your issue... for your reference, [here's a Git alias that uses __git_complete](https://github.com/sxlijin/.dotfiles/blob/master/git/config#L37). – Pockets Dec 01 '16 at 23:32