Guide to Maven 2.x auto completion using BASH

First you must go to the following site to install the BASH programmable auto completion setup if your distro doesn't have it by default. I don't think many do so you'll need to go to the Programmable Completion Website.

Once you've setup your system for auto completion you need to take the following:


  for mojo in $mojos
    export goals="$goals $plugin:$mojo"

  local cur goals

  goals='clean compile test install package deploy site'
  goals=$goals _m2_make_goals "eclipse" "eclipse"
  goals=$goals _m2_make_goals "idea" "idea"
  goals=$goals _m2_make_goals "assembly" "assembly"
  goals=$goals _m2_make_goals "plexus" "app bundle-application bundle-runtime descriptor runtime service"
  cur=`echo $cur | sed 's/\\\\//g'`
  COMPREPLY=($(compgen -W "${goals}" ${cur} | sed 's/\\\\//g') )

complete -F _m2_complete -o filenames mvn

And place it in /etc/bash_completion.d/m2. Once you've done that the next time you start up your BASH shell you will have m2 auto completion!