pyenv.plugin.zsh 1.25 KB
Newer Older
1
2
# This plugin loads pyenv into the current shell and provides prompt info via
# the 'pyenv_prompt_info' function. Also loads pyenv-virtualenv if available.
Stig Sandbeck Mathisen's avatar
Stig Sandbeck Mathisen committed
3

4
# Load pyenv only if command not already available
5
6
7
8
9
if command -v pyenv &> /dev/null && [[ "$(uname -r)" != *icrosoft* ]]; then
    FOUND_PYENV=1
else
    FOUND_PYENV=0
fi
10
11

if [[ $FOUND_PYENV -ne 1 ]]; then
12
    pyenvdirs=("$HOME/.pyenv" "/usr/local/pyenv" "/opt/pyenv" "/usr/local/opt/pyenv")
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
    for dir in $pyenvdirs; do
        if [[ -d $dir/bin ]]; then
            export PATH="$PATH:$dir/bin"
            FOUND_PYENV=1
            break
        fi
    done
fi

if [[ $FOUND_PYENV -ne 1 ]]; then
    if (( $+commands[brew] )) && dir=$(brew --prefix pyenv 2>/dev/null); then
        if [[ -d $dir/bin ]]; then
            export PATH="$PATH:$dir/bin"
            FOUND_PYENV=1
        fi
    fi
fi

if [[ $FOUND_PYENV -eq 1 ]]; then
32
33
34
    eval "$(pyenv init - zsh)"
    if (( $+commands[pyenv-virtualenv-init] )); then
        eval "$(pyenv virtualenv-init - zsh)"
35
    fi
36
37
38
39
40
41
42
43
    function pyenv_prompt_info() {
        echo "$(pyenv version-name)"
    }
else
    # fallback to system python
    function pyenv_prompt_info() {
        echo "system: $(python -V 2>&1 | cut -f 2 -d ' ')"
    }
Stig Sandbeck Mathisen's avatar
Stig Sandbeck Mathisen committed
44
fi
45

46
unset FOUND_PYENV pyenvdirs dir