mirror of
https://github.com/pyenv/pyenv.git
synced 2024-11-21 20:47:00 -05:00
43b28caa94
It's not that this is a preferred way to set a global version (one should use `rbenv global <version>` instead), but this fixes the function purely for correctness: all parent directories should be scanned, even the root directory. Fixes #745
34 lines
831 B
Bash
Executable file
34 lines
831 B
Bash
Executable file
#!/usr/bin/env bash
|
|
# Summary: Detect the file that sets the current rbenv version
|
|
set -e
|
|
[ -n "$RBENV_DEBUG" ] && set -x
|
|
|
|
find_local_version_file() {
|
|
local root="$1"
|
|
while true; do
|
|
if [ -e "${root}/.ruby-version" ]; then
|
|
echo "${root}/.ruby-version"
|
|
exit
|
|
elif [ -e "${root}/.rbenv-version" ]; then
|
|
echo "${root}/.rbenv-version"
|
|
exit
|
|
fi
|
|
[ -n "$root" ] || break
|
|
root="${root%/*}"
|
|
done
|
|
}
|
|
|
|
find_local_version_file "$RBENV_DIR"
|
|
[ "$RBENV_DIR" = "$PWD" ] || find_local_version_file "$PWD"
|
|
|
|
global_version_file="${RBENV_ROOT}/version"
|
|
|
|
if [ -e "$global_version_file" ]; then
|
|
echo "$global_version_file"
|
|
elif [ -e "${RBENV_ROOT}/global" ]; then
|
|
echo "${RBENV_ROOT}/global"
|
|
elif [ -e "${RBENV_ROOT}/default" ]; then
|
|
echo "${RBENV_ROOT}/default"
|
|
else
|
|
echo "$global_version_file"
|
|
fi
|