2011-08-12 05:33:45 -04:00
|
|
|
#!/usr/bin/env bash
|
2012-12-29 17:34:53 -05:00
|
|
|
# Summary: Show the current Ruby version
|
2011-08-12 05:33:45 -04:00
|
|
|
set -e
|
2011-09-12 11:11:59 -04:00
|
|
|
[ -n "$RBENV_DEBUG" ] && set -x
|
2011-08-09 16:41:35 -04:00
|
|
|
|
|
|
|
if [ -z "$RBENV_VERSION" ]; then
|
2011-08-18 15:11:40 -04:00
|
|
|
RBENV_VERSION_FILE="$(rbenv-version-file)"
|
|
|
|
RBENV_VERSION="$(rbenv-version-file-read "$RBENV_VERSION_FILE" || true)"
|
2011-08-09 16:41:35 -04:00
|
|
|
fi
|
|
|
|
|
2022-10-09 08:48:13 -04:00
|
|
|
IFS=$'\n' read -d '' -r -a scripts <<<"$(rbenv-hooks version-name)" || true
|
2015-05-27 23:10:39 -04:00
|
|
|
for script in "${scripts[@]}"; do
|
2022-10-09 08:48:13 -04:00
|
|
|
# shellcheck disable=SC1090
|
2015-05-27 23:10:39 -04:00
|
|
|
source "$script"
|
|
|
|
done
|
|
|
|
|
2011-09-09 16:52:31 -04:00
|
|
|
if [ -z "$RBENV_VERSION" ] || [ "$RBENV_VERSION" = "system" ]; then
|
|
|
|
echo "system"
|
2011-08-09 16:41:35 -04:00
|
|
|
exit
|
|
|
|
fi
|
|
|
|
|
2012-12-30 20:01:30 -05:00
|
|
|
version_exists() {
|
|
|
|
local version="$1"
|
|
|
|
[ -d "${RBENV_ROOT}/versions/${version}" ]
|
|
|
|
}
|
2011-08-09 16:41:35 -04:00
|
|
|
|
2012-12-30 20:01:30 -05:00
|
|
|
if version_exists "$RBENV_VERSION"; then
|
2011-08-09 16:41:35 -04:00
|
|
|
echo "$RBENV_VERSION"
|
2012-12-30 20:01:30 -05:00
|
|
|
elif version_exists "${RBENV_VERSION#ruby-}"; then
|
|
|
|
echo "${RBENV_VERSION#ruby-}"
|
2011-08-09 16:41:35 -04:00
|
|
|
else
|
2015-07-17 11:10:33 -04:00
|
|
|
echo "rbenv: version \`$RBENV_VERSION' is not installed (set by $(rbenv-version-origin))" >&2
|
2011-08-09 16:41:35 -04:00
|
|
|
exit 1
|
|
|
|
fi
|