Skip to content

Instantly share code, notes, and snippets.

@dharFr
Created August 23, 2012 16:05
Show Gist options
  • Save dharFr/3438077 to your computer and use it in GitHub Desktop.
Save dharFr/3438077 to your computer and use it in GitHub Desktop.
grailsenv - Dynamically switch your GRAILS_HOME

Usage

Copy the file content to your ~/.bashrc or save the grailsenv.sh file next to it and add . $HOME/grailsenv to your ~/.bashrc

NAME

grailsenv - Dynamically switch your GRAILS_HOME

SYNOPSIS

grailsenv [VERSION]

DESCRIPTION

Try to switch your GRAILS_HOME property to 'grails-VERSION' according to the current value

if a 'grails-VERSION' directory exists in the same folder, exports a new GRAILS_HOME and add it to the PATH

Without parameters, displays the current GRAILS_HOME value

# grailsenv - Dynamically switch your GRAILS_HOME
# grailsenv [VERSION]
# Try to switch your GRAILS_HOME property to 'grails-VERSION'
# according to the current value
#
# if a 'grails-VERSION' directory exists in the same folder,
# exports a new GRAILS_HOME and add it to the PATH
#
# Without parameters, displays the current GRAILS_HOME value
function grailsenv {
local __grails_parent=${GRAILS_HOME/\/grails*/}
if [ -v $1 ]; then
echo "GRAILS_HOME=$GRAILS_HOME"
ls "$__grails_parent/" | grep grails
elif [ -e "$__grails_parent/grails-$1" ]; then
export GRAILS_HOME="$__grails_parent/grails-$1"
export PATH=$GRAILS_HOME/bin:$PATH
echo "GRAILS_HOME=$GRAILS_HOME"
else
echo "$__grails_parent/grails-$1 doesn't exist... "
ls "$__grails_parent/" | grep grails
fi
}
oaudard@work:~/Projects/sample-grails-project$ grailsenv
GRAILS_HOME=/home/oaudard/dev-utils/grails
grails
grails-1.3.7
grails-1.3.8
grails-2.0.0
grails-2.0.1
grails-2.0.3
grails-2.0.4
grails-2.1.0
grails-2.1.0.zip
oaudard@work:~/Projects/sample-grails-project$ grailsenv 1.2
/home/oaudard/dev-utils/grails-1.2 doesn't exist...
grails
grails-1.3.7
grails-1.3.8
grails-2.0.0
grails-2.0.1
grails-2.0.3
grails-2.0.4
grails-2.1.0
grails-2.1.0.zip
oaudard@work:~/Projects/sample-grails-project$ grailsenv 2.1.0
GRAILS_HOME=/home/oaudard/dev-utils/grails-2.1.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment