Since I was using the command line quite a bit lately, and since there seems to be no shell extension for Ant, I was thinking that command completion specific for Ant would be of much help. For example you should be able to type "ant t" and then hit Tab and Bash will expand this to "ant test" (assuming there is a target called test and there are no other targets starting with t).
I vaguely knew that Bash does allow you to extend the command completion, the documentation confirmed that. After a bit of googeling and some luck it turned out that Ant does come with support for this, but this feature seems to be totally undocumented (I haven't seen this in any Ant docs). In the ant/bin folder there is a Perl file called complete-ant-cmd.pl. Check the comment at the top of the file for installation instructions. Under Cygwin I had to add "complete -C complete-ant-cmd.pl ant build.sh" to my .bashrc file and not "$ complete -C complete-ant-cmd ant build.sh" (no $ and add .pl to the command). Also, not sure why is build.sh needed in all this. Anyhow, after installing this extension command completion for Ant works great. It is a bit slow the very first time you use it but it creates a cache file called .ant-targets-... and then it is much faster.
Technorati Tags: 



Thanks! I ported the instructions to Mac OS X and linked back to this post.
Thanks for the link. I did not find Cygwin to be slower but every time the cache file is recreated it takes quite a while. It looks like it is running Ant in a subshell to get the targets (ant -p) and this is why it is so slow. The other drawback is that if the build file is broken for whatever reason then the tab completion will not work and it is quite confusing. It would be much better if the Perl scipt parsed the build file directly.
there is also a package called "bash completion" by ian macdonald that provides this functionality (and a ton of other tab completion shortcuts). it's available here: http://www.caliban.org/bash/index.shtml#completion
i used it shortly back in my programmer days, but i felt like it was extending the load-time for new cygwin windows, so i scrapped it. it might be better now a days though...
regards,
jhc.