jenv.plugin.zsh 897 B

123456789101112131415161718192021222324252627282930313233343536
  1. jenvdirs=("$HOME/.jenv" "/usr/local/bin/jenv" "/usr/local/jenv" "/opt/jenv")
  2. FOUND_JENV=0
  3. for jenvdir in $jenvdirs; do
  4. if [[ -d "${jenvdir}/bin" ]]; then
  5. FOUND_JENV=1
  6. break
  7. fi
  8. done
  9. if [[ $FOUND_JENV -eq 0 ]]; then
  10. if (( $+commands[brew] )) && jenvdir="$(brew --prefix jenv)"; then
  11. [[ -d "${jenvdir}/bin" ]] && FOUND_JENV=1
  12. fi
  13. fi
  14. if [[ $FOUND_JENV -eq 1 ]]; then
  15. (( $+commands[jenv] )) || export PATH="${jenvdir}/bin:$PATH"
  16. eval "$(jenv init - zsh)"
  17. function jenv_prompt_info() {
  18. local version="$(jenv version-name 2>/dev/null)"
  19. echo "${version:gs/%/%%}"
  20. }
  21. if [[ -d "${jenvdir}/versions" ]]; then
  22. export JENV_ROOT=$jenvdir
  23. fi
  24. else
  25. function jenv_prompt_info() {
  26. local version="$(java -version 2>&1 | cut -d' ' -f2)"
  27. echo "system: ${version:gs/%/%%}"
  28. }
  29. fi
  30. unset jenvdir jenvdirs FOUND_JENV