pyenv/libexec/pyenv-version-file

28 lines
642 B
Text
Raw Normal View History

# Usage: pyenv version-file [<dir>]
2013-01-18 08:41:41 +00:00
# Summary: Detect the file that sets the current pyenv version
set -e
[ -n "$PYENV_DEBUG" ] && set -x
target_dir="$1"
find_local_version_file() {
2014-01-06 07:37:21 +00:00
local root="$1"
while ! [[ "$root" =~ ^//[^/]*$ ]]; do
if [ -f "${root}/.python-version" ]; then
echo "${root}/.python-version"
return 0
fi
[ -n "$root" ] || break
root="${root%/*}"
done
return 1
}
if [ -n "$target_dir" ]; then
find_local_version_file "$target_dir"
else
find_local_version_file "$PYENV_DIR" || {
[ "$PYENV_DIR" != "$PWD" ] && find_local_version_file "$PWD"
} || echo "${PYENV_ROOT}/version"
fi