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.

67 lines
1.4 KiB

преди 11 години
преди 11 години
преди 10 години
преди 11 години
преди 10 години
преди 10 години
  1. #!/usr/bin/env bash
  2. #
  3. # Summary: Set or show the shell-specific Python version
  4. #
  5. # Usage: pyenv shell <version>
  6. # pyenv shell --unset
  7. #
  8. # Sets a shell-specific Python version by setting the `PYENV_VERSION'
  9. # environment variable in your shell. This version overrides local
  10. # application-specific versions and the global version.
  11. #
  12. # <version> should be a string matching a Python version known to pyenv.
  13. # The special version string `system' will use your default system Python.
  14. # Run `pyenv versions' for a list of available Python versions.
  15. set -e
  16. [ -n "$PYENV_DEBUG" ] && set -x
  17. # Provide pyenv completions
  18. if [ "$1" = "--complete" ]; then
  19. echo --unset
  20. echo system
  21. exec pyenv-versions --bare
  22. fi
  23. versions=("$@")
  24. shell="$(basename "${PYENV_SHELL:-$SHELL}")"
  25. if [ -z "$versions" ]; then
  26. if [ -z "$PYENV_VERSION" ]; then
  27. echo "pyenv: no shell-specific version configured" >&2
  28. exit 1
  29. else
  30. echo "echo \"\$PYENV_VERSION\""
  31. exit
  32. fi
  33. fi
  34. if [ "$versions" = "--unset" ]; then
  35. case "$shell" in
  36. fish )
  37. echo "set -e PYENV_VERSION"
  38. ;;
  39. * )
  40. echo "unset PYENV_VERSION"
  41. ;;
  42. esac
  43. exit
  44. fi
  45. # Make sure the specified version is installed.
  46. if pyenv-prefix "${versions[@]}" >/dev/null; then
  47. OLDIFS="$IFS"
  48. IFS=: version="${versions[*]}"
  49. IFS="$OLDIFS"
  50. case "$shell" in
  51. fish )
  52. echo "setenv PYENV_VERSION \"${version}\""
  53. ;;
  54. * )
  55. echo "export PYENV_VERSION=\"${version}\""
  56. ;;
  57. esac
  58. else
  59. echo "false"
  60. exit 1
  61. fi