2012-08-31 06:23:41 +00:00
|
|
|
#!/usr/bin/env bash
|
2016-03-02 01:39:52 +00:00
|
|
|
# Usage: pyenv version-file [<dir>]
|
2013-01-18 08:41:41 +00:00
|
|
|
# Summary: Detect the file that sets the current pyenv version
|
2012-08-31 06:23:41 +00:00
|
|
|
set -e
|
|
|
|
[ -n "$PYENV_DEBUG" ] && set -x
|
|
|
|
|
2016-03-02 01:39:52 +00:00
|
|
|
target_dir="$1"
|
|
|
|
|
2013-01-18 08:55:46 +00:00
|
|
|
find_local_version_file() {
|
2014-01-06 07:37:21 +00:00
|
|
|
local root="$1"
|
2016-03-02 01:39:52 +00:00
|
|
|
while ! [[ "$root" =~ ^//[^/]*$ ]]; do
|
2017-06-06 11:09:45 +00:00
|
|
|
if [ -f "${root}/.python-version" ]; then
|
2013-01-18 08:55:46 +00:00
|
|
|
echo "${root}/.python-version"
|
2016-03-02 01:39:52 +00:00
|
|
|
return 0
|
2013-01-18 08:55:46 +00:00
|
|
|
fi
|
2015-11-21 04:13:52 +00:00
|
|
|
[ -n "$root" ] || break
|
2013-01-18 08:55:46 +00:00
|
|
|
root="${root%/*}"
|
|
|
|
done
|
2016-03-02 01:39:52 +00:00
|
|
|
return 1
|
2013-01-18 08:55:46 +00:00
|
|
|
}
|
|
|
|
|
2016-03-02 01:39:52 +00:00
|
|
|
if [ -n "$target_dir" ]; then
|
|
|
|
find_local_version_file "$target_dir"
|
2012-08-31 06:23:41 +00:00
|
|
|
else
|
2016-03-02 01:39:52 +00:00
|
|
|
find_local_version_file "$PYENV_DIR" || {
|
|
|
|
[ "$PYENV_DIR" != "$PWD" ] && find_local_version_file "$PWD"
|
|
|
|
} || echo "${PYENV_ROOT}/version"
|
2012-08-31 06:23:41 +00:00
|
|
|
fi
|