Skip to content

Instantly share code, notes, and snippets.

@nobeans
Last active August 29, 2015 14:18
Show Gist options
  • Save nobeans/c16136700ae95cfe39be to your computer and use it in GitHub Desktop.
Save nobeans/c16136700ae95cfe39be to your computer and use it in GitHub Desktop.
GVM version switcher for Grails 2.x and 3.x
if [ `basename $SHELL` = "zsh" ]; then
if which gvm >/dev/null 2>&1; then
__gvm_switch_grails_griffon() {
# for 2.x
if [ -s "application.properties" ]; then
local array candidate target current
array=($(cat application.properties | grep --color=never 'app.\(grails\|griffon\).version' | sed -E "s|app.(.*).version=(.*)|\1 \2|g" | tr -d "\r\n"))
candidate=${array[1]}
target=${array[2]}
current=$((gvm offline enable >/dev/null && gvm current ${candidate} && gvm offline disable > /dev/null) | awk '{ print $4 }')
if [[ $current != $target ]]; then
echo "Switching to $candidate $target from $current..."
gvm use $candidate $target
fi
fi
# for 3.x
if [ -s "gradle.properties" ] && [ -d "grails-app" ]; then
local array candidate target current
array=($(cat gradle.properties | grep --color=never 'grailsVersion=' | sed -E "s|grailsVersion=(.*)|\1|g" | tr -d "\r\n"))
candidate=grails
target=${array[1]}
current=$((gvm offline enable >/dev/null && gvm current ${candidate} && gvm offline disable > /dev/null) | awk '{ print $4 }')
if [[ $current != $target ]]; then
echo "Switching to $candidate $target from $current..."
gvm use $candidate $target
fi
fi
}
add-zsh-hook chpwd __gvm_switch_grails_griffon
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment