mirror of
https://github.com/pyenv/pyenv.git
synced 2024-11-14 20:39:55 -05:00
9daf81f16e
Command `rbenv version-name > .ruby-version` will create an empty `.ruby-version` file before running `rbenv-version-file`. This causes `rbenv-version-file` to return empty string which in turn causes `rbenv-version-name` to return `system`. Ensure size of `.ruby-version` is non-zero as a workaround.
28 lines
658 B
Bash
Executable file
28 lines
658 B
Bash
Executable file
#!/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 [ -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
|