pyenv.plugin.zsh 1.2 KB

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