Home > grails, scripts > Updated bash completion script for OSX and Grails 1.1 & 1.2

Updated bash completion script for OSX and Grails 1.1 & 1.2

January 6th, 2010

Fernando Takai wrote an excellent bash completion script (also available here, originally from Ted Naleid), which makes calling Grails commands much easier.

Some examples:

Within a Grails application directory, listing all available commands:

myapp> grails [tab][tab]
bootstrap create-integration-test generate-controller list-plugins_ set-version
bug-report create-plugin_ generate-views package shell
clean create-script help_ package-plugin_ stats
compile create-service init plugin-info_ test-app
console create-tag-lib install-dependency release-plugin tomcat
create-app_ create-unit-test install-plugin run-app uninstall-plugin
create-controller dependency-report install-templates run-war upgrade
create-domain-class doc integrate-with schema-export war
create-filters generate-all list-plugin-updates set-proxy_

Within a Grails application directory, completing a command:

myapp> grails run-[tab][tab]
run-app run-war

Outside of a Grails application directory, listing all available commands:

home> grails [tab][tab]
create-app create-plugin help list-plugins package-plugin plugin-info set-proxy

Changes

I updated the script to adapt it to new Grails versions and made some minor changes:

* works with plugin provided scripts in Grails version >= 1.1, were plugins are stored under $HOME/.grails/grailsversion/projects/appname/plugins.
* detects the Grails version from $GRAILS_HOME instead of choosing the latest version from $HOME/.grails.
* adapts to different locations of plugins-list.xml, which changed with newer Grails versions
* does not need gawk (which is not installed by default on OSX)

My version of the script was tested with Grails 1.2 and OSX Snow Leopard and can be found at GitHub or below.

Installation

Save the script to an appropriate path (e.g. ~/bin/grails-bash-completion.sh)
[ -r ~/bin/grails-bash-completion.sh ] && source ~/bin/grails-bash-completion.sh

The complete Script

Categories: grails, scripts Tags:
  1. Shawn
    January 7th, 2010 at 18:01 | #1

    I’d like use your script but am a little unclear as to how go about it (I’m running Snow Leopard). Your instructions refer to ~/bin which doesn’t exist on my machine. I can create a bin directory under my user but I’m not how the script is going to be added to my path (which I normally set in my ~/.profile script

  2. jetztgradnet
    January 7th, 2010 at 18:03 | #2

    Hi Shawn,

    hm, I propably created the bin directory in my home folder myself and added it to my $PATH in .bashrc. But you can put this script anywhere you want. The dircetory containing this script does not need to be in your $PATH, just make sure you include the script in your .bashrc or .profile as mentionend in the blog post.

  3. Shawn
    January 7th, 2010 at 21:07 | #3

    @jetztgradnet

    Thanks. I added the script to my path–but all I get when typing grails [tab] [tab] is:

    grails grails-bash-completion.sh grails-debug

    whether I’m in a project directory or not.

  4. jetztgradnet
    January 8th, 2010 at 00:31 | #4

    Hi Thomas,

    first of all, you don’t need to add the script to the path, but you should source it in your .profile or .bashrc, like mentioned in the post.

    Before pressing tab, make sure, that there is a whitespace after the grails command, so grails is recognized as a (complete) command, instead of the start of a file name!

  5. January 9th, 2010 at 09:29 | #5

    very handy. I alias my most frequent commands but this would be very useful as well.

Comments are closed.
Fork me on GitHub