mirror of
https://github.com/pyenv/pyenv.git
synced 2024-11-21 20:47:00 -05:00
fe809ea90d
`default` was made legacy back in 2011 with
5be66da9f4
(the command was renamed from
`rbenv-default` to `rbenv-global`, and so the global file was renamed
from `$RBENV_ROOT/default` to `$RBENV_ROOT/global` (the latter taking
precedence)
`global` was then made legacy about a month later in Sep 2011 when the
preferred filename was changed to `$RBENV_ROOT/version`.
37 lines
867 B
Bash
Executable file
37 lines
867 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 [ -e "${root}/.ruby-version" ]; then
|
|
echo "${root}/.ruby-version"
|
|
return 0
|
|
elif [ -e "${root}/.rbenv-version" ]; then
|
|
echo "${root}/.rbenv-version"
|
|
return 0
|
|
fi
|
|
[ -n "$root" ] || break
|
|
root="${root%/*}"
|
|
done
|
|
return 1
|
|
}
|
|
|
|
find_global_version_file() {
|
|
local global_version_file="${RBENV_ROOT}/version"
|
|
|
|
echo "$global_version_file"
|
|
}
|
|
|
|
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"
|
|
} || find_global_version_file
|
|
fi
|