0aa645f8033ef86f8c8b0729a94fc54fbec49a25

Author
Marc Cornellà <marc.cornella@live.com>
Committer
GitHub <noreply@github.com>
Date

Message

pyenv: search the pyenv command if not found (#6811)

Diff

 1diff --git a/plugins/pyenv/pyenv.plugin.zsh b/plugins/pyenv/pyenv.plugin.zsh
 2index 76880e4157a56b7ffc6550e33010cf491a694366..dbc7da4728217de40a1aea2de13c24a9b0f43259 100644
 3--- a/plugins/pyenv/pyenv.plugin.zsh
 4+++ b/plugins/pyenv/pyenv.plugin.zsh
 5@@ -1,7 +1,29 @@
 6 # This plugin loads pyenv into the current shell and provides prompt info via
 7 # the 'pyenv_prompt_info' function. Also loads pyenv-virtualenv if available.
 8 
 9-if (( $+commands[pyenv] )); then
10+FOUND_PYENV=$+commands[pyenv]
11+
12+if [[ $FOUND_PYENV -ne 1 ]]; then
13+    pyenvdirs=("$HOME/.pyenv" "/usr/local/pyenv" "/opt/pyenv")
14+    for dir in $pyenvdirs; do
15+        if [[ -d $dir/bin ]]; then
16+            export PATH="$PATH:$dir/bin"
17+            FOUND_PYENV=1
18+            break
19+        fi
20+    done
21+fi
22+
23+if [[ $FOUND_PYENV -ne 1 ]]; then
24+    if (( $+commands[brew] )) && dir=$(brew --prefix pyenv 2>/dev/null); then
25+        if [[ -d $dir/bin ]]; then
26+            export PATH="$PATH:$dir/bin"
27+            FOUND_PYENV=1
28+        fi
29+    fi
30+fi
31+
32+if [[ $FOUND_PYENV -eq 1 ]]; then
33     eval "$(pyenv init - zsh)"
34     if (( $+commands[pyenv-virtualenv-init] )); then
35         eval "$(pyenv virtualenv-init - zsh)"
36@@ -15,3 +37,5 @@ else
37         echo "system: $(python -V 2>&1 | cut -f 2 -d ' ')"
38     }
39 fi
40+
41+unset FOUND_PYENV dir