Skip to content

Instantly share code, notes, and snippets.

@brianm
Created July 2, 2014 18:41
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 brianm/503993b9207b62ed2c19 to your computer and use it in GitHub Desktop.
Save brianm/503993b9207b62ed2c19 to your computer and use it in GitHub Desktop.
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
}
function _setjdk_completion (){
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment