Customizing completion in Prezto ZSH for git function

700 views Asked by At

I recently switched from bash to zsh and am using Prezto for basic setup. For a long time I've used this function:

function g() {
  if [[ $# > 0 ]]; then
    git $@
  else
    git status
  fi
}

This allows me to use g for git status or g <command> for any other git action.

The Prezto git module had an alias that was overriding my function alias g='git'

So I commented this out and my function worked as expected. However the problem comes in when I need tab completion.

ex:

I have thus far been unable to marry using my function with the git completion modules so that I can do things like g checkout aw-<tab> and have it show me the branch options.

I had this working fine in bash and would love to be able to have similar functionality in zsh.

Thank you in advance!

1

There are 1 answers

0
Omer Tuchfeld On BEST ANSWER

Add this to your ~/.zshrc

compdef g=git

As explained here