2011-08-18 19:11:40 +00:00
|
|
|
#!/usr/bin/env bash
|
2015-12-23 14:19:54 +00:00
|
|
|
# Usage: rbenv version-file [<dir>]
|
2012-12-29 22:34:53 +00:00
|
|
|
# Summary: Detect the file that sets the current rbenv version
|
2011-08-18 19:11:40 +00:00
|
|
|
set -e
|
2011-09-12 15:11:59 +00:00
|
|
|
[ -n "$RBENV_DEBUG" ] && set -x
|
2011-08-18 19:11:40 +00:00
|
|
|
|
2015-12-23 14:19:54 +00:00
|
|
|
target_dir="$1"
|
|
|
|
|
2012-12-27 19:39:36 +00:00
|
|
|
find_local_version_file() {
|
|
|
|
local root="$1"
|
2015-12-23 14:19:54 +00:00
|
|
|
while ! [[ "$root" =~ ^//[^/]*$ ]]; do
|
2012-12-31 00:35:08 +00:00
|
|
|
if [ -e "${root}/.ruby-version" ]; then
|
|
|
|
echo "${root}/.ruby-version"
|
2015-12-23 14:19:54 +00:00
|
|
|
return 0
|
2012-12-27 19:39:36 +00:00
|
|
|
fi
|
2015-06-09 15:24:15 +00:00
|
|
|
[ -n "$root" ] || break
|
2012-12-27 19:39:36 +00:00
|
|
|
root="${root%/*}"
|
|
|
|
done
|
2015-12-23 14:19:54 +00:00
|
|
|
return 1
|
2012-12-27 19:39:36 +00:00
|
|
|
}
|
|
|
|
|
2015-12-23 14:19:54 +00:00
|
|
|
if [ -n "$target_dir" ]; then
|
|
|
|
find_local_version_file "$target_dir"
|
2011-08-18 19:32:33 +00:00
|
|
|
else
|
2015-12-23 14:19:54 +00:00
|
|
|
find_local_version_file "$RBENV_DIR" || {
|
|
|
|
[ "$RBENV_DIR" != "$PWD" ] && find_local_version_file "$PWD"
|
2015-12-29 13:44:32 +00:00
|
|
|
} || echo "${RBENV_ROOT}/version"
|
2011-08-18 19:32:33 +00:00
|
|
|
fi
|