Over a million developers have joined DZone.
Platinum Partner

Bash Completion for Maven

· Java Zone

The Java Zone is brought to you in partnership with AppDynamics. Discover how AppDynamics steps in to upgrade your performance game and prevent your enterprise from these top 10 Java performance problems.

Based on a blog post by John Hitchings on the WealthFront Engineering web site, I started looking into bash completion.

As a Java developer, I use Maven from the command-line quite a bit, so I decided to add bash completion for the ‘mvn’ command.

The following script works great on OS X, and should work in bash on other systems as well.

Happy completion!

_mvn()
{
local cur prev opts
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
opts="clean compile package install"

if [[ ${cur} == * ]] ; then
COMPREPLY=( $(compgen -W "${opts}" ${cur}) )
return 0
fi
}
complete -F _mvn mvn

From http://greybeardedgeek.net/2011/02/bash-completion-for-maven/

The Java Zone is brought to you in partnership with AppDynamics. AppDynamics helps you gain the fundamentals behind application performance, and implement best practices so you can proactively analyze and act on performance problems as they arise, and more specifically with your Java applications. Start a Free Trial.

Topics:

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}