mirror of
https://github.com/wahyd4/jabba.git
synced 2026-08-09 21:06:46 +10:00
25 lines
438 B
Go
25 lines
438 B
Go
package command
|
|
|
|
import (
|
|
"os/exec"
|
|
"strings"
|
|
"github.com/shyiko/jabba/cfg"
|
|
"path"
|
|
)
|
|
|
|
var lookPath = exec.LookPath
|
|
|
|
func Current() string {
|
|
javaPath, err := lookPath("java")
|
|
if err == nil {
|
|
prefix := path.Join(cfg.Dir(), "jdk") + "/"
|
|
if strings.HasPrefix(javaPath, prefix) {
|
|
index := strings.Index(javaPath[len(prefix):], "/")
|
|
if index != -1 {
|
|
return javaPath[len(prefix):len(prefix) + index]
|
|
}
|
|
}
|
|
}
|
|
return ""
|
|
}
|