jenv.plugin.zsh 710 Bytes
Newer Older
John Burwell's avatar
John Burwell committed
1
2
3
jenvdirs=("$HOME/.jenv" "/usr/local/jenv" "/opt/jenv")

FOUND_JENV=0
4
5
for jenvdir in $jenvdirs; do
    if [[ -d "${jenvdir}/bin" ]]; then
John Burwell's avatar
John Burwell committed
6
        FOUND_JENV=1
7
8
9
        break
    fi
done
John Burwell's avatar
John Burwell committed
10

11
12
13
if [[ $FOUND_JENV -eq 0 ]]; then
    if (( $+commands[brew] )) && jenvdir="$(brew --prefix jenv)"; then
        FOUND_JENV=1
John Burwell's avatar
John Burwell committed
14
    fi
15
16
17
18
19
20
21
22
23
fi

if [[ $FOUND_JENV -eq 1 ]]; then
    export PATH="${jenvdir}/bin:$PATH"
    eval "$(jenv init - zsh)"

    function jenv_prompt_info() { jenv version-name 2>/dev/null }

    if [[ -d "${jenvdir}/versions" ]]; then
John Burwell's avatar
John Burwell committed
24
25
        export JENV_ROOT=$jenvdir
    fi
26
else
John Burwell's avatar
John Burwell committed
27
28
    function jenv_prompt_info() { echo "system: $(java -version 2>&1 | cut -f 2 -d ' ')" }
fi
29

Marc Cornellà's avatar
Marc Cornellà committed
30
unset jenvdir jenvdirs FOUND_JENV