Coach Thrasher

Monday May 28, 2007

Fixing Maven 2.x BASH auto completion on CYGWIN

I just figured out how to turn on auto completion for Maven 2.x commands from my cygwin shell on WinXP using bash_completion. The Apache Maven site is getting flushed out with documentation, and they've put up a mini guide for Maven 2.x auto completion. However, it didn't work out the box.

To fix it, I had to:

1) Run the cygwin's "setup.exe" and add the "bash-completion: Bash completion enhancements" package (version 20060301-2) to my cygwin install (bash v3.2.9-10 was already installed).

2) Configure the cygwin bash shell to use bash_completion. I found out how to do this from the cygwin-announce mailing list archive, but I extended their notes to apply the change to all users. It's not enabled by default, even after it's installed, so to add bash_completion for all users, you have to manually edit the /etc/bash.bashrc (usually at "c:/cygwin/etc/bash.bashrc") and add this line:

source /etc/bash_completion

3) Get the auto completion script and follow the instructions to install it to the file:

/etc/bash_completion.d/m2

4) Now, fix a bug in the script which keeps it from running on cygwin. This is the bug:

mvn ecl[TAB]-bash: ${ COMP_WORDS[COMP_CWORD]}: bad substitution

Fix it by editing /etc/bash_completion.d/m2 and changing this line (removing the extra space):

cur=${ COMP_WORDS[COMP_CWORD]}

to this:

cur=${COMP_WORDS[COMP_CWORD]}

Restart the xterm for this to take effect. Now, when you type:

mvn eclip[TAB]

the auto-completion will turn it into:

mvn eclipse:eclipse

Other Maven commands will auto-complete as well. You can add commands for new plugins by editing the m2 file. If you want to really make the auto-completion command set scale for Maven commands, checkout how it's done in GlassFish by Harsha. He has a commands.txt file that is read by the bash_completion.d script for GlassFish. The same thing could be setup for Maven commands.

Yay for saving the fingers from some typing!

Comments:

Post a Comment:
Comments are closed for this entry.

Calendar

Feeds

Search

Links

Navigation

Referrers