mirror of
https://github.com/pyenv/pyenv.git
synced 2024-11-21 20:47:00 -05:00
110 lines
2.2 KiB
Bash
Executable file
110 lines
2.2 KiB
Bash
Executable file
#!/usr/bin/env bash
|
|
set -e
|
|
export -n CDPATH
|
|
|
|
if [ "$1" = "--debug" ]; then
|
|
export PYENV_DEBUG=1
|
|
shift
|
|
fi
|
|
|
|
if [ -n "$PYENV_DEBUG" ]; then
|
|
export PS4='+ [${BASH_SOURCE##*/}:${LINENO}] '
|
|
set -x
|
|
fi
|
|
|
|
if enable -f "${0%/*}"/../libexec/pyenv-realpath.dylib realpath 2>/dev/null; then
|
|
abs_dirname() {
|
|
local path="$(realpath "$1")"
|
|
echo "${path%/*}"
|
|
}
|
|
else
|
|
if [ -n "$PYENV_NATIVE_EXT" ]; then
|
|
echo "pyenv: failed to load \`realpath' builtin" >&2
|
|
exit 1
|
|
fi
|
|
READLINK=$(type -p greadlink readlink | head -1)
|
|
if [ -z "$READLINK" ]; then
|
|
echo "pyenv: cannot find readlink - are you missing GNU coreutils?" >&2
|
|
exit 1
|
|
fi
|
|
|
|
resolve_link() {
|
|
$READLINK "$1"
|
|
}
|
|
|
|
abs_dirname() {
|
|
local cwd="$(pwd)"
|
|
local path="$1"
|
|
|
|
while [ -n "$path" ]; do
|
|
cd "${path%/*}"
|
|
local name="${path##*/}"
|
|
path="$(resolve_link "$name" || true)"
|
|
done
|
|
|
|
pwd
|
|
cd "$cwd"
|
|
}
|
|
fi
|
|
|
|
if [ -z "${PYENV_ROOT}" ]; then
|
|
PYENV_ROOT="${HOME}/.pyenv"
|
|
else
|
|
PYENV_ROOT="${PYENV_ROOT%/}"
|
|
fi
|
|
export PYENV_ROOT
|
|
|
|
if [ -z "${PYENV_DIR}" ]; then
|
|
PYENV_DIR="$(pwd)"
|
|
else
|
|
cd "$PYENV_DIR" 2>/dev/null || {
|
|
echo "pyenv: cannot change working directory to \`$PYENV_DIR'"
|
|
exit 1
|
|
} >&2
|
|
PYENV_DIR="$(pwd)"
|
|
cd "$OLDPWD"
|
|
fi
|
|
export PYENV_DIR
|
|
|
|
|
|
shopt -s nullglob
|
|
|
|
bin_path="$(abs_dirname "$0")"
|
|
for plugin_bin in "${PYENV_ROOT}/plugins/"*/bin; do
|
|
PATH="${plugin_bin}:${PATH}"
|
|
done
|
|
export PATH="${bin_path}:${PATH}"
|
|
|
|
PYENV_HOOK_PATH="${PYENV_HOOK_PATH}:${PYENV_ROOT}/pyenv.d"
|
|
if [ "${bin_path%/*}" != "$PYENV_ROOT" ]; then
|
|
# Add pyenv's own `pyenv.d` unless pyenv was cloned to PYENV_ROOT
|
|
PYENV_HOOK_PATH="${PYENV_HOOK_PATH}:${bin_path%/*}/pyenv.d"
|
|
fi
|
|
PYENV_HOOK_PATH="${PYENV_HOOK_PATH}:/usr/local/etc/pyenv.d:/etc/pyenv.d:/usr/lib/pyenv/hooks"
|
|
for plugin_hook in "${PYENV_ROOT}/plugins/"*/etc/pyenv.d; do
|
|
PYENV_HOOK_PATH="${PYENV_HOOK_PATH}:${plugin_hook}"
|
|
done
|
|
export PYENV_HOOK_PATH
|
|
|
|
shopt -u nullglob
|
|
|
|
|
|
command="$1"
|
|
case "$command" in
|
|
"" | "-h" | "--help" )
|
|
echo -e "$(pyenv---version)\n$(pyenv-help)" >&2
|
|
;;
|
|
"-v" )
|
|
exec pyenv---version
|
|
;;
|
|
* )
|
|
command_path="$(command -v "pyenv-$command" || true)"
|
|
if [ -z "$command_path" ]; then
|
|
echo "pyenv: no such command \`$command'" >&2
|
|
exit 1
|
|
fi
|
|
|
|
shift 1
|
|
exec "$command_path" "$@"
|
|
;;
|
|
esac
|