Blog An exploration of the art and
craft of software development

Rake task completion

Posted by Marty Haught on Tuesday, October 31, 2006

I’m a huge fan of code/command completion. So you can imagine that not having code completion for Rake commands was a disappointment. It’s not like I had task completion for Ant so it wasn’t really based on something I had before. However, I saw some posts several months back on how to enable command completion with your rake file. Unfortunately I was so busy that I put off investigating it until later. Well, I finally had some time to sit down with it.

First, let me say that all the hard work was done before I started looking at how you do it. So I want to acknowledge all the talented folks who blazed this trail. Second, this process while it only took me a few hours was fairly inspiring to see how I could write a cool script in Ruby and have it do tab completion in bash. Chalk that up to my lack of experience with scripting in bash.

Anyway, my modification of this script was to not only make it recognize nested tasks in your rake files but to cache the rake tasks due to the sluggishness if you read the Rake output each time. Again, I borrowed both of these concepts from others in the community. It’s completely possible that many have already done this so I don’t claim to have the only version that does this. After all it does seem like a logical step to add all these features in. Without further ado, feel free to download the script and use it yourself. Here are some basic install instructions.

  • Download the rake-complete.rb file and save it in some directory of your preference.
  • Add this line to your .bashrc:
    complete -C /path/to/rake-complete.rb -o default rake

That’s it. Enjoy! Oh, one more thing, I added a list of credits to those that I borrowed the script from in the comments of the rake-complete.rb file.

blog comments powered by Disqus