better java handling

This commit is contained in:
Chen Asraf
2022-02-15 15:27:13 +02:00
parent 50cc5bc87d
commit 987d5cfe38
4 changed files with 55 additions and 16 deletions

View File

@@ -20,9 +20,6 @@ export DOTFILES="$HOME/.dotfiles"
export MANPATH="$HOME/.dotfiles/man:$MANPATH"
export LDFLAGS="-L/opt/homebrew/opt/flex/lib"
export CPPFLAGS="-I/opt/homebrew/opt/flex/include"
export JAVA_8_HOME="/Library/Java/JavaVirtualMachines/jdk1.8.0_321.jdk/Contents/Home/"
export JAVA_11_HOME="/Library/Java/JavaVirtualMachines/jdk-11.0.12.jdk/Contents/Home/"
export JAVA_17_HOME="/Library/Java/JavaVirtualMachines/jdk-17.0.1.jdk/Contents/Home/"
export ANDROID_HOME="$HOME/Library/Android/sdk"
# Ruby User Install (for CocoaPods)

13
home.sh
View File

@@ -47,7 +47,11 @@ __home_do_install() {
__home_print_help() {
__home_prepare_dir -q
man ./man_src/home.7
if [[ "$1" == "0" ]]; then
man -P cat ./man_src/home.7
else
man ./man_src/home.7
fi
__home_revert_dir -q
}
@@ -64,9 +68,16 @@ home() {
if [[ $# -gt 0 ]]; then
case "$1" in
git)
__home_prepare_dir
shift
git $@
__home_revert_dir
;;
pull)
__home_prepare_dir
git pull
reload-zsh
__home_revert_dir
;;
push)

View File

@@ -16,9 +16,11 @@ before running the supplied command
.SH OPTIONS
home takes one command:
push Push updates to git
git Run arbitrary git commands from .dotfiles directory
pull Pull updates from git
push Add all files, commit and push updates to git
pull Pull updates from git and reload
reload, rl Reload (source) the current shell

View File

@@ -1,33 +1,62 @@
#!/usr/bin/env bash
java() {
echo $JAVA_HOME
$JAVA_HOME/bin/java $@
}
jver_file="$HOME/.jver"
__list_jvers__() {
ls /Library/Java/JavaVirtualMachines
}
jver() {
ver="$1"
if [[ "$ver" == "list" ]]; then
echo
echo_cyan "All installed versions on this machine:"
echo
__list_jvers__ | tr " " "\n"
echo
echo_yellow 'You can use "jver [version]" to switch to the required version.'
echo_yellow 'Supplying the [version] is done via grep, so can support partial matches or patterns.'
echo_yellow 'For example, "jver 17" will match correctly for "jdk-17.0.2.jdk"'
return 0
fi
quiet="$2"
if [[ $ver == "" ]]; then
echo "No version supplied. Usage: jver [version]"
return 1
fi
found=$(eval "echo \$JAVA_${ver}_HOME")
count=$(__list_jvers__ | grep -i $ver -c)
found=$(__list_jvers__ | grep -i $ver)
if [[ "$found" == "" ]]; then
echo "Version $ver not found"
echo "Possible versions are:"
env | grep -E 'JAVA_[0-9]+_HOME'
echo "(use only the number, e.g. 8)"
if [[ $count -gt 1 ]]; then
echo_red "Multiple versions found:"
echo
echo_red $found | tr " " "\n"
echo
echo_red "Please use a more specific pattern so that only one result matches"
return 2
fi
export JAVA_HOME="$found"
if [[ "$found" == "" ]]; then
echo_red "Version $ver not found"
echo_yellow "Possible versions are:"
env | grep -E 'JAVA_[0-9]+_HOME'
echo_yellow "(use only the number, e.g. 8)"
return 2
fi
export JAVA_HOME="/Library/Java/JavaVirtualMachines/$found/Contents/Home"
touch $jver_file
echo $ver >$jver_file
echo $found >$jver_file
if [[ $quiet != '-q' ]]; then
echo "JAVA_HOME=$found"
echo_cyan "Found version: $found"
echo
java -version
fi
}