pyenv/libexec/rbenv-version-name
2022-10-09 14:48:13 +02:00

34 lines
867 B
Bash
Executable file

#!/usr/bin/env bash
# Summary: Show the current Ruby version
set -e
[ -n "$RBENV_DEBUG" ] && set -x
if [ -z "$RBENV_VERSION" ]; then
RBENV_VERSION_FILE="$(rbenv-version-file)"
RBENV_VERSION="$(rbenv-version-file-read "$RBENV_VERSION_FILE" || true)"
fi
IFS=$'\n' read -d '' -r -a scripts <<<"$(rbenv-hooks version-name)" || true
for script in "${scripts[@]}"; do
# shellcheck disable=SC1090
source "$script"
done
if [ -z "$RBENV_VERSION" ] || [ "$RBENV_VERSION" = "system" ]; then
echo "system"
exit
fi
version_exists() {
local version="$1"
[ -d "${RBENV_ROOT}/versions/${version}" ]
}
if version_exists "$RBENV_VERSION"; then
echo "$RBENV_VERSION"
elif version_exists "${RBENV_VERSION#ruby-}"; then
echo "${RBENV_VERSION#ruby-}"
else
echo "rbenv: version \`$RBENV_VERSION' is not installed (set by $(rbenv-version-origin))" >&2
exit 1
fi