pyenv/libexec/rbenv-version-file

29 lines
658 B
Text
Raw Normal View History

#!/usr/bin/env bash
# Usage: rbenv version-file [<dir>]
# Summary: Detect the file that sets the current rbenv version
set -e
[ -n "$RBENV_DEBUG" ] && set -x
target_dir="$1"
find_local_version_file() {
local root="$1"
while ! [[ "$root" =~ ^//[^/]*$ ]]; do
if [ -e "${root}/.ruby-version" ]; then
echo "${root}/.ruby-version"
return 0
fi
[ -n "$root" ] || break
root="${root%/*}"
done
return 1
}
if [ -n "$target_dir" ]; then
find_local_version_file "$target_dir"
2011-08-18 15:32:33 -04:00
else
find_local_version_file "$RBENV_DIR" || {
[ "$RBENV_DIR" != "$PWD" ] && find_local_version_file "$PWD"
} || echo "${RBENV_ROOT}/version"
2011-08-18 15:32:33 -04:00
fi