Skip to content

Instantly share code, notes, and snippets.

@finnjohnsen
Created October 16, 2012 13:10
Show Gist options
  • Save finnjohnsen/3899180 to your computer and use it in GitHub Desktop.
Save finnjohnsen/3899180 to your computer and use it in GitHub Desktop.
auto switches symlinks to your grails project
#!/bin/bash
# This is ~/.auto_grails_switch, and it switches your grails runtime.
# 1. add this file to the bottom of ~/.bashrc
# source ~/.auto_grails_switch.sh
# 2. Make sure .auto_grails_switch is run every time you change dir. add \$(auto_grails_switch) to PS1
# PS1='debian_chroot:+($debian_chroot)}\$(auto_grails_switch)\$ '
# 3. make a grails symlink for the first time.
# ln -sf /opt/grails-2.0.0 /opt/grails
# 4. Update the GRAILS_INSTALLATIONS variable.
# 5. restart your shell and you're done.
GRAILS_INSTALLATIONS=/opt
function switch_grails {
if [ "$(stat -c %N $GRAILS_INSTALLATIONS/grails | cut -d '>' -f2 | tr -d ' ' )" != "$(stat -c %N $GRAILS_INSTALLATIONS/grails-$1)" ]
then
#echo 'setting'
rm -f $GRAILS_INSTALLATIONS/grails
ln -sf $GRAILS_INSTALLATIONS/grails-$1 $GRAILS_INSTALLATIONS/grails
fi
}
function auto_grails_switch {
if [ -e "application.properties" ]
then
GRAILS_TARGET_VERSION=$(grep "app.grails.version" application.properties | cut -d"=" -f2)
if [ $GRAILS_TARGET_VERSION ]
then
switch_grails $GRAILS_TARGET_VERSION
fi
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment