Skip to content

Commit

Permalink
Added support for ~/.jvmconfig file
Browse files Browse the repository at this point in the history
closes #4
  • Loading branch information
caarlos0 committed Mar 18, 2015
1 parent 6485f49 commit e0ec073
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,14 @@ jvm local 7

On OSX, `jvm` will use the `java_home` tool to find the available versions. For
Ubuntu, right now `jvm` has `/usr/lib/jvm/java-${version}-oracle/` hard coded.
This might change soon.
This might change soon. If you need custom versions, like `6-openjdk`, for
example, you can run `jvm config` and add a line like this:

```
6-openjdk=/path/to/openjdk/6
```

And `jvm` will automagically works.

### `jvm` commands

Expand All @@ -46,6 +53,8 @@ Right now, `jvm` has the following commands:
version;
- `global VERSION`: creates a `.java-version` in your `$HOME` dir with the given
version;
- `jvm config`: opens the `~/.jvmconfig` file in your default `$EDITOR`. Useful
for defining custom version and/or paths;
- `version`: shows current version;
- `help`: shows the help.

Expand Down
19 changes: 17 additions & 2 deletions jvm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
_jvm_set-java-path() {
local version="$1"
local previous_java_home="$JAVA_HOME"
if [ -d "/usr/lib/jvm/java-${version}-oracle/" ]; then
if [ -f ~/.jvmconfig ]; then
local new_java_home="$(grep "${version}"= ~/.jvmconfig | cut -f2 -d'=')"
elif [ -d "/usr/lib/jvm/java-${version}-oracle/" ]; then
local new_java_home="/usr/lib/jvm/java-${version}-oracle/"
elif [ -e /usr/libexec/java_home ]; then
local new_java_home="$(/usr/libexec/java_home -v 1."$version")"
Expand Down Expand Up @@ -36,6 +38,16 @@ _jvm-discover-and-set-version() {
[ ! -z "$version" ] && _jvm_set-java-path "$version"
}

_jvm-edit-config() {
if [ ! -f ~/.jvmconfig ]; then
cat > ~/.jvmconfig <<EOF
7=Path to jdk 7
8=Path to jdk 8
EOF
fi
$EDITOR ~/.jvmconfig
}

jvm() {
if [ "$#" != 0 ]; then
local command="$1"; shift
Expand All @@ -55,8 +67,11 @@ jvm() {
reload)
_jvm-discover-and-set-version
;;
config)
_jvm-edit-config
;;
*)
echo "Usage: jvm (local|global|version|reload) <args>"
echo "Usage: jvm (local|global|version|reload|config) <args>"
return 0
;;
esac
Expand Down

0 comments on commit e0ec073

Please sign in to comment.