Custom Directory Completion for Zsh

I've been planing on checking zsh out ever since I found out about oh-my-zsh. This weekend I finally had a little free time to do so. Besides a pretty informative prompt and useful command completion, one thing that I (now) find absolutely necessary in any shell I use daily it my custom make_dir_complete function to generate shortcuts for any directory. I've previously described how to implement it here, if you're interested.

Well, given zsh's fame of having a really complicated completion system, I was reluctant to go down the path of implementing it on my own and decided to check on #zsh (at Freenode) if anyone had already done what I wanted or if I could at least get some decent directions (zsh's completion documentation is exactly like bash's. They both suck). Since the only answer I got was in the form of "I've asked that previously and got no answer", I decided to give it a shot.

I went down the same chain of thought I had to use on bash: generate a completion function which would reply the next possible directories based on the first parameter. Turns out this was a really bad choice, since I soon got stuck at not getting consecutive completions and started feeling confused by the many glob options available.

After messing around with existing system completions (basic ones, like the man completion), I found some really interesting uses of compctl and decided to delve deep into it's manpages and soon I came up with this:

function jk() { cd ~/src/$@; };
compctl -/ -W ~/src jk

And that's it, it worked! I was impressed, even completing a directory with spaces worked out of the box. Now I just had to add the code generation part and would be all set:

make_dir_complete() {
    local aliasname=$1
    local dirname=$(readlink -f $2)
    FUNC="$aliasname () { cd $dirname/\$@ }"
    eval $FUNC
    compctl -/ -W $dirname $aliasname
}

Short, concise and way easier to "get it" than it's bash's counterpart. I've even created a oh-my-zsh plugin for using it, it's the same function, but with proper usage documentation and parameter verifications. You can check it here.

So, all my requirements were met and I was ready to ditch bash in favor of zsh, right? Unfortunately no. I've spent the Sunday using it, was quite happy and everything was going smooth, until I decided to do a test-drive and check how it fared against my current job workflow, which involves a slightly large git repository (migrated from svn by yours truly). That's when I came back running to bash. A great part of my job involves reviewing code, and the shell completion helps me a lot matching the branches I'll review and merge and zsh's git completion crawls like a zombie (a slow one, without legs).

A fully migrated setup, with every important thing working properly, discarded without remorse. I'm not willing to change shells and lose productivity, even if the community behind oh-my-zsh is big and amazing. So long zsh, I'll be back (soon, I hope) when your git completion doesn't take more time to list possibilities than it takes me to remember and type a branch name.