I got some basic rake command line completion working today using Jon Baer’s comment. Very simple, very easy:
However this didn’t work for the namespaced tasks in a rails app like rake test:units
. Searching a little further I found a reference to some code Nicholas Seckar wrote on project.ioni.st. This used ruby to find the possible tasks for command completion. This looked promising, but it still didn’t work for namespaced tasks. A little more googling led me to what looked like the perfect link: Rake-completion script that handles namespaces. Alas, it only handled one level of namespacing. It worked nicely for rake test:units
, but rake tmp:ses<TAB>
would complete to rake tmp:clear
instead of rake tmp:sessions:clear
. Also, rake test:units <TAB>
would complete to rake test:units units
instead of giving me all the tasks again, just in case you want to run multiple tasks form the command line.
So, now what? Stand on the shoulders of others, naturally. Here is what I’m using now that handles multiple namespaces and multiple tasks per command line: