2012-08-31 02:23:41 -04:00
|
|
|
#!/usr/bin/env bash
|
2013-01-18 03:41:41 -05:00
|
|
|
#
|
|
|
|
# Summary: Set or show the shell-specific Python version
|
|
|
|
#
|
|
|
|
# Usage: pyenv shell <version>
|
|
|
|
# pyenv shell --unset
|
|
|
|
#
|
|
|
|
# Sets a shell-specific Python version by setting the `PYENV_VERSION'
|
|
|
|
# environment variable in your shell. This version overrides local
|
|
|
|
# application-specific versions and the global version.
|
|
|
|
#
|
|
|
|
# <version> should be a string matching a Python version known to pyenv.
|
|
|
|
# The special version string `system' will use your default system Python.
|
|
|
|
# Run `pyenv versions' for a list of available Python versions.
|
|
|
|
|
2012-08-31 02:23:41 -04:00
|
|
|
set -e
|
|
|
|
[ -n "$PYENV_DEBUG" ] && set -x
|
|
|
|
|
|
|
|
# Provide pyenv completions
|
|
|
|
if [ "$1" = "--complete" ]; then
|
|
|
|
echo --unset
|
|
|
|
echo system
|
|
|
|
exec pyenv-versions --bare
|
|
|
|
fi
|
|
|
|
|
2012-09-07 06:16:42 -04:00
|
|
|
versions=("$@")
|
2012-08-31 02:23:41 -04:00
|
|
|
|
2012-09-07 06:16:42 -04:00
|
|
|
if [ -z "$versions" ]; then
|
2012-08-31 06:39:29 -04:00
|
|
|
if [ -z "$PYENV_VERSION" ]; then
|
2012-08-31 02:23:41 -04:00
|
|
|
echo "pyenv: no shell-specific version configured" >&2
|
|
|
|
exit 1
|
|
|
|
else
|
2012-08-31 07:12:26 -04:00
|
|
|
echo "echo \"\$PYENV_VERSION\""
|
2012-08-31 02:23:41 -04:00
|
|
|
exit
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2012-09-07 06:16:42 -04:00
|
|
|
if [ "$versions" = "--unset" ]; then
|
2012-08-31 06:39:29 -04:00
|
|
|
echo "unset PYENV_VERSION"
|
2013-01-18 04:57:08 -05:00
|
|
|
exit
|
2012-08-31 02:23:41 -04:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Make sure the specified version is installed.
|
2013-01-27 22:53:18 -05:00
|
|
|
if pyenv-prefix "${versions[@]}" >/dev/null; then
|
2013-01-18 04:57:08 -05:00
|
|
|
IFS=: PYENV_VERSION="${versions[*]}"
|
|
|
|
echo "export PYENV_VERSION=\"${PYENV_VERSION}\""
|
|
|
|
else
|
|
|
|
echo "return 1"
|
|
|
|
exit 1
|
|
|
|
fi
|