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