Edit Grails files with Gedit and Gred on Linux
May 15th 2010 Posted at Grails, Groovy, Linux
11 Comments
When working on a Grails project, I generally prefer using text editors over heavyweight IDEs. They seem to give me more flexibility and agility than their bulky counterparts. For Groovy and Grails in particular, I favour using the great Gnome text editor gedit.
Using this editor by itself does come with limitations since it knows nothing about Grails. Next, you can give it wings by installing additional helper files found in the gedit-grails-bundle. This will add Groovy syntax highlighting, bundles, and many other nice features like tab completion for the grails command on the command line. After this has been installed, and all instructions have been followed, gedit should be fully functional and ready to work on your Grails project. It should function much like TextMate on Mac OS X.
I began to realize that despite all of this, one thing was missing: I wanted to invoke gedit from the command line like I invoke the grails script. Wouldn’t it be great if you had a script to do this? In steps gred! It is my attempt at doing just this. It is a script that can be placed on your path, helping you to get to your files fast!
If you have Git installed, get it off github like this:
git clone git://github.com/marcoVermeulen/scripts.git
As super user, place the script in the gred folder on your path, and make it executable:
# cp scripts/gred/gred /usr/local/bin/ # chmod +x /usr/local/bin/gred
A listing of this script can also be found at the end of my post.
In order to use the script, ensure that you have the following line in your ~/.bashrc file:
export EDITOR="/usr/bin/gedit"
Also ensure that you already have gedit running before running gred the first time.
Now change to the directory of your project:
cd myproject
By simply entering the command, you will receive the following help:
Usage: gred <domain class> [option]
options:
-tests : open all unit and itegration tests.
-unit : open unit tests
-integration : open integration tests
-int : open integration tests
-builder : open test object builders
-controller : open controller
-service : open all services
-views : open all .gsp files for domain classAn example of using this script:
Having a User domain class with unit and integration tests in your Grails project,
you can open gedit on all the related artifacts by simply typing:
> gred user -all
If you only wanted to see the integration test, you could type:
> gred user -integration
or simply
> gred user -int
It is also noteworthy that the name of the domain class can be written in a case-insensitive
way for convenience.
As promised, here follows the listing. This is subject to change as I improve and expand the script. It might be worth pulling from github from time to time in case I make some updates. Since the code is changing so often, it’s becoming difficult to maintain it in two places. I’ve resorted to only updating the version on GitHub.
If you have any suggestions of how you would like the script improved, please drop me a comment.
Thanks for reading, and hope you enjoy the script!
Cheers,
Marco.
You can leave a response, or trackback from your own site.


would be cool to add this to the wiki page http://groovy.codehaus.org/Other+Plugins
Just added it to the wiki page…
Would love to see a Griffon version of gred
I prefer using grails in VIM in Linux, any idea on how to debug without an IDE?
The nice thing about the gred script is that you can use it with any editor on your system. Simply set the EDITOR variable in .bashrc as described in my post.
For debugging, I generally use good old logging, and drop back to IntelliJ when I really need to use breakpoints. That doesn’t happen too often though…
I also love using vim, but it still doesn’t support Groovy very well. It seems to expect semi-colons at the end of every line, and that’s not Groovy at all
I added the option of editing the grails-app/conf file
if [ "$OPTION" = '-conf' -o "$OPTION" = '-all' ]; then
case $INPUT in
data*) FILE_NAME=’*Data*’;;
boot*) FILE_NAME=’*Boot*’;;
config*) FILE_NAME=’*Config*’;;
map*) FILE_NAME=’*Map*’;;
*) FILE_NAME=’*';;
esac
DIR_PORTION=’grails-app/conf’
find $DIR_PORTION -iname “$FILE_NAME” | grep -v .svn | xargs -0 -r “$EDITOR”
fi
As for vim check the groovy syntax file here: http://www.vim.org/scripts/script.php?script_id=945
Thanks Pascal. I’ve included your functionality into my script and pushed it to GitHub. I’ve also added some other functionality that displays the plain text test results when invoking gred with -reports.
Andres, I’ll look at doing a Griffon version in the future as well. Promise! How does griffed sound?
Hi Andres,
I’ve finally had some time to write a Griffon version of Gred. It’s called Griffed and is available at my scripts project in Github:
http://github.com/marcoVermeulen/scripts
Let me know if you want any changes/enhancements made!
Cheers,
Marco.
Awesome! Saw your tweet too. Thanks!
cool stuff! Thanks for posting. I will link to this in the gedit-grails-bundle somehow
Thanks! That would be great!