pyenv/libexec/rbenv-version-file
Richie Thomas 906a6acc10
version-file docs update (#1512)
Update rbenv-version-file docs to indicate that the returned version file may or may not actually exist.

Co-authored-by: Mislav Marohnić <git@mislav.net>
2023-07-11 17:38:36 +02:00

34 lines
889 B
Bash
Executable file

#!/usr/bin/env bash
# Usage: rbenv version-file [<dir>]
# Summary: Detect the file that sets the current rbenv version
#
# Detects and prints the location of a `.ruby-version` file that sets the
# version for the current working directory. If no file found, this prints
# the location of the global version file, even if that file does
# not exist.
set -e
[ -n "$RBENV_DEBUG" ] && set -x
target_dir="$1"
find_local_version_file() {
local root="$1"
while ! [[ "$root" =~ ^//[^/]*$ ]]; do
if [ -s "${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"
else
find_local_version_file "$RBENV_DIR" || {
[ "$RBENV_DIR" != "$PWD" ] && find_local_version_file "$PWD"
} || echo "${RBENV_ROOT}/version"
fi