2011-08-18 15:11:40 -04:00
|
|
|
#!/usr/bin/env bash
|
2012-12-29 17:34:53 -05:00
|
|
|
# Summary: Detect the file that sets the current rbenv version
|
2011-08-18 15:11:40 -04:00
|
|
|
set -e
|
2011-09-12 11:11:59 -04:00
|
|
|
[ -n "$RBENV_DEBUG" ] && set -x
|
2011-08-18 15:11:40 -04:00
|
|
|
|
2012-12-27 14:39:36 -05:00
|
|
|
find_local_version_file() {
|
|
|
|
local root="$1"
|
|
|
|
while [ -n "$root" ]; do
|
2012-12-30 19:35:08 -05:00
|
|
|
if [ -e "${root}/.ruby-version" ]; then
|
|
|
|
echo "${root}/.ruby-version"
|
|
|
|
exit
|
|
|
|
elif [ -e "${root}/.rbenv-version" ]; then
|
2012-12-27 14:39:36 -05:00
|
|
|
echo "${root}/.rbenv-version"
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
root="${root%/*}"
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
find_local_version_file "$RBENV_DIR"
|
|
|
|
[ "$RBENV_DIR" = "$PWD" ] || find_local_version_file "$PWD"
|
2011-08-18 15:11:40 -04:00
|
|
|
|
2011-09-28 10:45:58 -04:00
|
|
|
global_version_file="${RBENV_ROOT}/version"
|
2011-08-18 15:32:33 -04:00
|
|
|
|
2011-09-28 10:45:58 -04:00
|
|
|
if [ -e "$global_version_file" ]; then
|
|
|
|
echo "$global_version_file"
|
|
|
|
elif [ -e "${RBENV_ROOT}/global" ]; then
|
|
|
|
echo "${RBENV_ROOT}/global"
|
|
|
|
elif [ -e "${RBENV_ROOT}/default" ]; then
|
|
|
|
echo "${RBENV_ROOT}/default"
|
2011-08-18 15:32:33 -04:00
|
|
|
else
|
2011-09-28 10:45:58 -04:00
|
|
|
echo "$global_version_file"
|
2011-08-18 15:32:33 -04:00
|
|
|
fi
|