2012-08-31 06:23:41 +00:00
|
|
|
#!/usr/bin/env bash
|
2013-01-18 08:41:41 +00: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 06:23:41 +00: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 10:16:42 +00:00
|
|
|
versions=("$@")
|
2013-12-26 04:48:43 +00:00
|
|
|
shell="$(basename "${PYENV_SHELL:-$SHELL}")"
|
2012-08-31 06:23:41 +00:00
|
|
|
|
2012-09-07 10:16:42 +00:00
|
|
|
if [ -z "$versions" ]; then
|
2012-08-31 10:39:29 +00:00
|
|
|
if [ -z "$PYENV_VERSION" ]; then
|
2012-08-31 06:23:41 +00:00
|
|
|
echo "pyenv: no shell-specific version configured" >&2
|
|
|
|
exit 1
|
|
|
|
else
|
2012-08-31 11:12:26 +00:00
|
|
|
echo "echo \"\$PYENV_VERSION\""
|
2012-08-31 06:23:41 +00:00
|
|
|
exit
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2012-09-07 10:16:42 +00:00
|
|
|
if [ "$versions" = "--unset" ]; then
|
2013-09-30 09:02:12 +00:00
|
|
|
case "$shell" in
|
|
|
|
fish )
|
|
|
|
echo "set -e PYENV_VERSION"
|
|
|
|
;;
|
|
|
|
* )
|
|
|
|
echo "unset PYENV_VERSION"
|
|
|
|
;;
|
|
|
|
esac
|
2013-01-18 09:57:08 +00:00
|
|
|
exit
|
2012-08-31 06:23:41 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Make sure the specified version is installed.
|
2013-01-28 03:53:18 +00:00
|
|
|
if pyenv-prefix "${versions[@]}" >/dev/null; then
|
2013-08-15 13:29:14 +00:00
|
|
|
OLDIFS="$IFS"
|
2014-01-02 13:26:22 +00:00
|
|
|
IFS=: version="${versions[*]}"
|
2013-08-15 13:29:14 +00:00
|
|
|
IFS="$OLDIFS"
|
2013-09-30 09:02:12 +00:00
|
|
|
case "$shell" in
|
|
|
|
fish )
|
2014-01-02 13:26:22 +00:00
|
|
|
echo "setenv PYENV_VERSION \"${version}\""
|
2013-09-30 09:02:12 +00:00
|
|
|
;;
|
|
|
|
* )
|
2014-01-02 13:26:22 +00:00
|
|
|
echo "export PYENV_VERSION=\"${version}\""
|
2013-09-30 09:02:12 +00:00
|
|
|
;;
|
|
|
|
esac
|
2013-01-18 09:57:08 +00:00
|
|
|
else
|
2013-09-30 09:02:12 +00:00
|
|
|
echo "false"
|
2013-01-18 09:57:08 +00:00
|
|
|
exit 1
|
|
|
|
fi
|