How to get ZSH to complete CMD1 like CMD2

by gabebw

I tested out git-achievements (my achievements are here), and it seemed like a fun little toy. Then, I did this (with alias git=git-achievements in my zshrc):

git <TAB>

aaaand, nothing. Just completion of files in the current directory. Where’d my ZSH git completion go?! Why didn’t it work across aliases?

My initial reaction was just to remove the git-achievements alias and use straight git. Then I decided to enter the Lair of the ZSH Completion Docs* and see if I could fix it. My first attempt was to edit my zshrc to add all the git completion functions to git-achievements:

alias git="git-achievements"
compdef git-achievements git-add git-am <...etc...> git-write-tree

Note that these were copied from /usr/share/zsh/4.3.9/functions/_git. That didn’t work. So I dove back in and found it:

compdef [ -an ] function names… [ -[pP] patterns… [ -N names… ] ]

…all the arguments may have the form `cmd=service‘. Here service should already have been defined by `cmd1=service‘ lines in #compdef files, as described above. The argument for cmd will be completed in the same way as service. [bolding mine]

Even that is hard to puzzle out, but it means that you can do this:

alias git="git-achievements"
compdef git-achievements=git

..and everything is fine and dandy.

*Note: I know that the ZSH documentation writers must be trying, and it’s mostly clear(ish), or at least comprehensive. But there’s so many options that it’s basically a hopeless task. I mean, I found this tip out on something like my 10th read of that page.

Advertisements