Skip to content

Instantly share code, notes, and snippets.

@patforna
Created August 12, 2014 10:46
Show Gist options
  • Save patforna/afcc627df7eb15e0ea9d to your computer and use it in GitHub Desktop.
Save patforna/afcc627df7eb15e0ea9d to your computer and use it in GitHub Desktop.
function addToPath() {
export PATH=$1:$PATH
}
function removeFromPath() {
export PATH=$(echo $PATH | sed -E -e "s;:$1;;" -e "s;$1:?;;")
}
# switch between different jdk versions. usage: jdk 1.7
function jdk() {
if [ $# -ne 0 ]; then
if [ -n "${JAVA_HOME+x}" ]; then
removeFromPath $JAVA_HOME
fi
export JAVA_HOME="$HOME/Dropbox/system/java/jdk$@/Contents/Home"
addToPath $JAVA_HOME/bin
fi
java -version 2>&1 | head -n 1
}
# default to JDK 1.7 for new shells
jdk 1.7 > /dev/null
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment