Skip to content

Instantly share code, notes, and snippets.

@jamescookie
Last active September 19, 2020 19:37
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jamescookie/f33e445830694660c2a747f074592d1f to your computer and use it in GitHub Desktop.
Save jamescookie/f33e445830694660c2a747f074592d1f to your computer and use it in GitHub Desktop.
To switch JAVA_HOME in the current YADR zsh shell on a mac put this file in .zsh.after
function setJavaHome
{
javaVersions=($(/usr/libexec/java_home -V 2>&1 | grep x86 | awk -F ":" '{print $1}' | awk -F "," '{print $1}' | xargs echo -n))
newJava=""
while [[ $newJava = "" ]]; do
echo "Select your Java version for this shell"
select newJava in ${javaVersions[@]}; do
if [[ $newJava = "" ]]; then
echo "Please enter a valid option."
else
export JAVA_HOME=$(/usr/libexec/java_home -v $newJava)
echo $(java -version)
fi
break
done
done
}
@jamescookie
Copy link
Author

Should work in a bash profile too, but you might have to change line 3 to be:
read -a javaVersions <<<$(/usr/libexec/java_home -V 2>&1 | grep x86 | awk -F ":" '{print $1}' | awk -F "," '{print $1}' | xargs echo -n)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment