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.

28 rivejä
662 B

  1. #!/usr/bin/env bash
  2. # Usage: pyenv version-file [<dir>]
  3. # Summary: Detect the file that sets the current pyenv version
  4. set -e
  5. [ -n "$PYENV_DEBUG" ] && set -x
  6. target_dir="$1"
  7. find_local_version_file() {
  8. local root="$1"
  9. while ! [[ "$root" =~ ^//[^/]*$ ]]; do
  10. if [ -f "${root}/.python-version" ]; then
  11. echo "${root}/.python-version"
  12. return 0
  13. fi
  14. [ -n "$root" ] || break
  15. root="${root%/*}"
  16. done
  17. return 1
  18. }
  19. if [ -n "$target_dir" ]; then
  20. find_local_version_file "$target_dir"
  21. else
  22. find_local_version_file "$PYENV_DIR" || {
  23. [ "$PYENV_DIR" != "$PWD" ] && find_local_version_file "$PWD"
  24. } || echo "${PYENV_ROOT}/version"
  25. fi