Better bash completion for rake

A while ago, I started searching for decent bash completion for rake. At the time I was disappointed by the available solutions, so I hacked together my own and have been steadily improving it since then. It’s available at gist.github.

I think it still has some advantages over other solutions that have been posted:

  • It completes long options (--trace, --execute-print, etc.).

  • It falls back to completing filenames. I find this most useful for running just one set of tests, e.g.:

    $ rake test:units TEST=test/unit/
    bar_test.rb  foo_test.rb  helpers/
  • It handles colons for namespaced tasks correctly, without resorting to setting COMP_WORDBREAKS globally.

  • It doesn’t rely on an external script, which means it only has to fire up one Ruby interpreter (to run rake) instead of two (to run a Ruby completion script that runs rake).

It doesn’t cache the task list, so it still requires a call to rake --tasks on every <TAB>. I may add caching support later.

Here it is for your inspection and enjoyment:


About this entry