| 1 | #!/usr/bin/env bash |
| 2 | # |
| 3 | # Summary: Set or show the global Python version(s) |
| 4 | # |
| 5 | # Usage: pyenv global <version> <version2> <..> |
| 6 | # |
| 7 | # Sets the global Python version(s). You can override the global version at |
| 8 | # any time by setting a directory-specific version with `pyenv local' |
| 9 | # or by setting the `PYENV_VERSION' environment variable. |
| 10 | # |
| 11 | # <version> can be specified multiple times and should be a version |
| 12 | # tag known to pyenv. The special version string `system' will use |
| 13 | # your default system Python. Run `pyenv versions' for a list of |
| 14 | # available Python versions. |
| 15 | # |
| 16 | # Example: To enable the python2.7 and python3.7 shims to find their |
| 17 | # respective executables you could set both versions with: |
| 18 | # |
| 19 | # 'pyenv global 3.7.0 2.7.15' |
| 20 | # |
| 21 | |
| 22 | |
| 23 | set -e |
| 24 | [ -n "$PYENV_DEBUG" ] && set -x |
| 25 | |
| 26 | # Provide pyenv completions |
| 27 | if [ "$1" = "--complete" ]; then |
| 28 | echo system |
| 29 | exec pyenv-versions --bare |
| 30 | fi |
| 31 | |
| 32 | versions=("$@") |
| 33 | PYENV_VERSION_FILE="${PYENV_ROOT}/version" |
| 34 | |
| 35 | if [ -n "$versions" ]; then |
| 36 | pyenv-version-file-write "$PYENV_VERSION_FILE" "${versions[@]}" |
| 37 | else |
| 38 | OLDIFS="$IFS" |
| 39 | IFS=: versions=($( |
| 40 | pyenv-version-file-read "$PYENV_VERSION_FILE" || |
| 41 | pyenv-version-file-read "${PYENV_ROOT}/global" || |
| 42 | pyenv-version-file-read "${PYENV_ROOT}/default" || |
| 43 | echo system |
| 44 | )) |
| 45 | IFS="$OLDIFS" |
| 46 | for version in "${versions[@]}"; do |
| 47 | echo "$version" |
| 48 | done |
| 49 | fi |