You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 rivejä
1.1 KiB

11 vuotta sitten
  1. #!/usr/bin/env bash
  2. # Summary: List all Python versions available to pyenv
  3. # Usage: pyenv versions [--bare]
  4. #
  5. # Lists all Python versions found in `$PYENV_ROOT/versions/*'.
  6. set -e
  7. [ -n "$PYENV_DEBUG" ] && set -x
  8. if [ "$1" = "--bare" ]; then
  9. hit_prefix=""
  10. miss_prefix=""
  11. current_versions=()
  12. version_origin=""
  13. include_system=""
  14. else
  15. hit_prefix="* "
  16. miss_prefix=" "
  17. OLDIFS="$IFS"
  18. IFS=: current_versions=($(pyenv-version-name || true))
  19. IFS="$OLDIFS"
  20. version_origin=" (set by $(pyenv-version-origin))"
  21. include_system="1"
  22. fi
  23. array_exists() {
  24. local x car="$1"
  25. shift
  26. for x in "$@"; do
  27. [ "${x}" = "${car}" ] && return 0
  28. done
  29. return 1
  30. }
  31. print_version() {
  32. if array_exists "$1" "${current_versions[@]}"; then
  33. echo "${hit_prefix}$1${version_origin}"
  34. else
  35. echo "${miss_prefix}$1"
  36. fi
  37. }
  38. # Include "system" in the non-bare output, if it exists
  39. if [ -n "$include_system" ] && PYENV_VERSION=system pyenv-which python >/dev/null 2>&1; then
  40. print_version system
  41. fi
  42. for path in "${PYENV_ROOT}/versions/"*; do
  43. if [ -d "$path" ]; then
  44. print_version "${path##*/}"
  45. fi
  46. done