Cached Rake tab completion for bash

A while back, Projectionist posted a handy Rake tab-completion script by Nicholas Seckar. I loved it at first, but after a while I found it slow as hell. It has to run rake --tasks every time, which leads to a cavernous multi-second lag when you’re looking to complete a command-line.

So here’s my improvement: It caches the Rake output for future tab-completes. The cache should generally be smart enough to stay up-to-date, although it will get fooled if you’ve got Rakefiles including Rakefiles including Rakefiles. If the cache gets stupid you can just wipe it out by deleting ~/.rake/tc_cache/.

Incidentally, the colons in namespaced tasks also confuse the tab-completion like no tomorrow. Personally I’m not sure if namespaces are really good idea in Rakefiles, but that’s another issue entirely.

(Blake Watters seems to have done the same thing, though his packaging of it as a plugin would appear to make it Rails-specific. I haven’t tried his plugin, but maybe it’ll be a more convenient install for you if you’re one of those curious people who’s never worked on a Ruby project that’s not Rails.)

blog comments powered by Disqus

« Previous post

Next post »