2011-08-02 23:11:41 +00:00
|
|
|
#!/usr/bin/env bash -e
|
2011-08-01 20:50:26 +00:00
|
|
|
|
|
|
|
read_version_file() {
|
|
|
|
egrep -m 1 '[^[:space:]]' "$1"
|
|
|
|
}
|
|
|
|
|
|
|
|
find_version_file() {
|
2011-08-02 17:21:30 +00:00
|
|
|
local root="$(pwd)"
|
2011-08-01 20:50:26 +00:00
|
|
|
while [ -n "$root" ]; do
|
|
|
|
if [ -e "${root}/.rbenv-version" ]; then
|
|
|
|
echo "${root}/.rbenv-version"
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
root="${root%/*}"
|
|
|
|
done
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
find_default_version_file() {
|
2011-08-02 17:21:30 +00:00
|
|
|
local default_path="$HOME/.rbenv/default"
|
2011-08-01 20:50:26 +00:00
|
|
|
if [ -e "$default_path" ]; then
|
|
|
|
echo "$default_path"
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
if [ -z "$RBENV_VERSION" ]; then
|
|
|
|
RBENV_VERSION_FILE="$(find_version_file || find_default_version_file || true)"
|
|
|
|
|
|
|
|
if [ -n "$RBENV_VERSION_FILE" ]; then
|
|
|
|
RBENV_VERSION="$(read_version_file "$RBENV_VERSION_FILE")"
|
|
|
|
else
|
|
|
|
echo "rbenv: no default version specified" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2011-08-03 13:39:56 +00:00
|
|
|
if [ "$RBENV_VERSION" = "system" ]; then
|
|
|
|
echo "$RBENV_VERSION"
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
|
2011-08-01 20:50:26 +00:00
|
|
|
RBENV_VERSION_PATH="${HOME}/.rbenv/versions/${RBENV_VERSION}"
|
|
|
|
|
|
|
|
if [ -d "$RBENV_VERSION_PATH" ]; then
|
|
|
|
echo "$RBENV_VERSION"
|
|
|
|
else
|
|
|
|
echo "rbenv: version \`$RBENV_VERSION' is not installed" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|