Created
April 20, 2013 16:09
-
-
Save dain/5426469 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
function setjdk { | |
local ver=${1?Usage: setjdk <version>} | |
export JAVA_HOME=$(/usr/libexec/java_home -v $ver) | |
PATH=$(echo $PATH | tr ':' '\n' | grep -v Java | tr '\n' ':') | |
export PATH=$JAVA_HOME/bin:$PATH | |
java -version | |
echo "JAVA_HOME $JAVA_HOME"; | |
} | |
function setjdk-quiet { | |
local ver=${1?Usage: setjdk <version>} | |
export JAVA_HOME=$(/usr/libexec/java_home -v $ver) | |
PATH=$(echo $PATH | tr ':' '\n' | grep -v Java | tr '\n' ':') | |
export PATH=$JAVA_HOME/bin:$PATH | |
} | |
function _setjdk_completion (){ | |
COMPREPLY=() | |
COMPREPLY=() | |
local cur=${COMP_WORDS[COMP_CWORD]//\\\\/} | |
local options=$(/usr/libexec/java_home -x | plutil -convert json -r -o - - | grep JVMVersion | sed 's/[^:]*[^"]*"\([^"]*\).*/\1/') | |
COMPREPLY=($(compgen -W "${options}" ${cur})) | |
} | |
complete -F _setjdk_completion -o filenames setjdk | |
complete -F _setjdk_completion -o filenames defaultjdk |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment