Skip to content

Instantly share code, notes, and snippets.

@ganta
Forked from kiy0taka/gist:4387787
Last active December 12, 2015 01:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ganta/4689233 to your computer and use it in GitHub Desktop.
Save ganta/4689233 to your computer and use it in GitHub Desktop.
Modified to follow symbolic links.
__gvm_switch() {
if [ -s "application.properties" ]; then
local arr candidate candidate_home 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]}
candidate_home=$(eval echo '$'$(echo $candidate | tr '[:lower:]' '[:upper:]')_HOME)
if [ ! -z "$(readlink $candidate_home)" ]; then
candidate_home=$(readlink $candidate_home)
fi
current=$(echo $candidate_home | sed -e "s_$GVM_DIR/$candidate/__g")
if [[ $current != $target ]]; then
echo "Switching to $candidate $target ..."
gvm use $candidate $target
fi
fi
}
chpwd() {
__gvm_switch
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment