Accept "ruby-" version prefix but print a warning to stderr

This commit is contained in:
Sam Stephenson 2012-12-30 19:01:30 -06:00
parent b974bf54dc
commit 5e52fae7c1
2 changed files with 11 additions and 3 deletions

View file

@ -13,10 +13,18 @@ if [ -z "$RBENV_VERSION" ] || [ "$RBENV_VERSION" = "system" ]; then
exit
fi
RBENV_VERSION_PATH="${RBENV_ROOT}/versions/${RBENV_VERSION}"
version_exists() {
local version="$1"
[ -d "${RBENV_ROOT}/versions/${version}" ]
}
if [ -d "$RBENV_VERSION_PATH" ]; then
if version_exists "$RBENV_VERSION"; then
echo "$RBENV_VERSION"
elif version_exists "${RBENV_VERSION#ruby-}"; then
{ echo "rbenv: ignoring extraneous \`ruby-' prefix in version \`${RBENV_VERSION}'"
echo "(set by $(rbenv-version-origin))"
} >&2
echo "${RBENV_VERSION#ruby-}"
else
echo "rbenv: version \`$RBENV_VERSION' is not installed" >&2
exit 1

View file

@ -21,7 +21,7 @@ fi
print_version() {
if [ "$1" == "$current_version" ]; then
echo "${hit_prefix}$(rbenv-version)"
echo "${hit_prefix}$(rbenv-version 2>/dev/null)"
else
echo "${miss_prefix}$1"
fi