pyenv.plugin.zsh 1.1 KB

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