Skip to content

Instantly share code, notes, and snippets.

@kiy0taka
Last active December 10, 2015 05:28
Show Gist options
  • Save kiy0taka/4387787 to your computer and use it in GitHub Desktop.
Save kiy0taka/4387787 to your computer and use it in GitHub Desktop.
GVM Grails/Griffon auto switch for zsh.
__gvm_switch() {
if [ -s "gradle.properties" ]; then
local candidate current target
candidate=grails
target=$(cat gradle.properties | grep --color=never 'grailsVersion' | sed "s_grailsVersion=\(.*\)_\1_g")
if [[ $target != '' ]]; then
current=$(eval echo '$'$(echo $candidate | tr '[:lower:]' '[:upper:]')_HOME | sed -e "s_$GVM_DIR/$candidate/__g")
if [[ $current != $target ]]; then
echo "Switching to $candidate $target ..."
gvm offline enable > /dev/null
gvm use $candidate $target
gvm offline disable > /dev/null
fi
fi
fi
if [ -s "application.properties" ]; then
local arr candidate current target
arr=($(cat application.properties | grep --color=never 'app.\(grails\|griffon\).version' | sed "s_app.\(.*\).version=\(.*\)_\1 \2_g"))
candidate=${arr[1]}
target=${arr[2]}
current=$(eval echo '$'$(echo $candidate | tr '[:lower:]' '[:upper:]')_HOME | sed -e "s_$GVM_DIR/$candidate/__g")
if [[ $current != $target ]]; then
echo "Switching to $candidate $target ..."
gvm offline enable > /dev/null
gvm use $candidate $target
gvm offline disable > /dev/null
fi
fi
}
chpwd() {
__gvm_switch
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment