1#!/usr/bin/env bash 2# Summary: Show the current Ruby version 3set -e 4[ -n "$RBENV_DEBUG" ] && set -x 5 6if [ -z "$RBENV_VERSION" ]; then 7 RBENV_VERSION_FILE="$(rbenv-version-file)" 8 RBENV_VERSION="$(rbenv-version-file-read "$RBENV_VERSION_FILE" || true)" 9fi 10 11OLDIFS="$IFS" 12IFS=$'\n' scripts=(`rbenv-hooks version-name`) 13IFS="$OLDIFS" 14for script in "${scripts[@]}"; do 15 source "$script" 16done 17 18if [ -z "$RBENV_VERSION" ] || [ "$RBENV_VERSION" = "system" ]; then 19 echo "system" 20 exit 21fi 22 23version_exists() { 24 local version="$1" 25 [ -d "${RBENV_ROOT}/versions/${version}" ] 26} 27 28if version_exists "$RBENV_VERSION"; then 29 echo "$RBENV_VERSION" 30elif version_exists "${RBENV_VERSION#ruby-}"; then 31 echo "${RBENV_VERSION#ruby-}" 32else 33 echo "rbenv: version \`$RBENV_VERSION' is not installed (set by $(rbenv-version-origin))" >&2 34 exit 1 35fi 36