pyenv.plugin.zsh 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. # Load pyenv only if command not already available
  4. if command -v pyenv &> /dev/null && [[ "$(uname -r)" != *icrosoft* ]]; then
  5. FOUND_PYENV=1
  6. else
  7. FOUND_PYENV=0
  8. fi
  9. if [[ $FOUND_PYENV -ne 1 ]]; then
  10. pyenvdirs=("$HOME/.pyenv" "/usr/local/pyenv" "/opt/pyenv" "/usr/local/opt/pyenv")
  11. for dir in $pyenvdirs; do
  12. if [[ -d $dir/bin ]]; then
  13. export PATH="$PATH:$dir/bin"
  14. FOUND_PYENV=1
  15. break
  16. fi
  17. done
  18. fi
  19. if [[ $FOUND_PYENV -ne 1 ]]; then
  20. if (( $+commands[brew] )) && dir=$(brew --prefix pyenv 2>/dev/null); then
  21. if [[ -d $dir/bin ]]; then
  22. export PATH="$PATH:$dir/bin"
  23. FOUND_PYENV=1
  24. fi
  25. fi
  26. fi
  27. if [[ $FOUND_PYENV -eq 1 ]]; then
  28. eval "$(pyenv init - --no-rehash zsh)"
  29. if (( $+commands[pyenv-virtualenv-init] )); then
  30. eval "$(pyenv virtualenv-init - zsh)"
  31. fi
  32. function pyenv_prompt_info() {
  33. echo "$(pyenv version-name)"
  34. }
  35. else
  36. # fallback to system python
  37. function pyenv_prompt_info() {
  38. echo "system: $(python -V 2>&1 | cut -f 2 -d ' ')"
  39. }
  40. fi
  41. unset FOUND_PYENV pyenvdirs dir