pyenv/libexec/pyenv-versions
2013-01-18 19:09:56 +09:00

41 lines
848 B
Bash
Executable file

#!/usr/bin/env bash
# Summary: List all Python versions available to pyenv
# Usage: pyenv versions [--bare]
#
# Lists all Python versions found in `$PYENV_ROOT/versions/*'.
set -e
[ -n "$PYENV_DEBUG" ] && set -x
array_exists() {
local x car="$1"
shift
for x in "$@"; do
[ "${x}" = "${car}" ] && return 0
done
return 1
}
IFS=: PYENV_VERSION_NAMES=($(pyenv-version-name))
if [ "$1" = "--bare" ]; then
hit_prefix=""
miss_prefix=""
version_origin=""
else
hit_prefix="* "
miss_prefix=" "
version_origin=" (set by $(pyenv-version-origin))"
fi
for path in "${PYENV_ROOT}/versions/"*; do
if [ -d "$path" ]; then
version="${path##*/}"
if array_exists "$version" "${PYENV_VERSION_NAMES[@]}"; then
echo "${hit_prefix}${version}${version_origin}"
else
echo "${miss_prefix}${version}"
fi
fi
done