jenv.plugin.zsh 848 Bytes
Newer Older
John Burwell's avatar
John Burwell committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
_homebrew-installed() {
    type brew &> /dev/null
}

_jenv-from-homebrew-installed() {
    brew --prefix jenv &> /dev/null
}

jenvdirs=("$HOME/.jenv" "/usr/local/jenv" "/opt/jenv")
if _homebrew-installed && _jenv-from-homebrew-installed ; then
    jenvdirs+=($(brew --prefix jenv) "${jenvdirs[@]}")
fi

FOUND_JENV=0
for jenvdir in "${jenvdirs[@]}" ; do
    if [ -d $jenvdir/bin -a $FOUND_JENV -eq 0 ] ; then
        FOUND_JENV=1
        export PATH="${jenvdir}/bin:$PATH"
        eval "$(jenv init - zsh)"

        function jenv_prompt_info() {
          echo "$(jenv version-name)"
        }
    fi
    if [ -d $jenvdir/versions -a $FOUND_JENV -eq 0 ] ; then
        export JENV_ROOT=$jenvdir
    fi
done
unset jenvdir

if [ $FOUND_JENV -eq 0 ] ; then
    function jenv_prompt_info() { echo "system: $(java -version 2>&1 | cut -f 2 -d ' ')" }
fi