diff --git a/libexec/rbenv-hooks b/libexec/rbenv-hooks index 6291e78a..010c7058 100755 --- a/libexec/rbenv-hooks +++ b/libexec/rbenv-hooks @@ -9,6 +9,8 @@ set -e if [ "$1" = "--complete" ]; then echo exec echo rehash + echo version-name + echo version-origin echo which exit fi diff --git a/libexec/rbenv-version-name b/libexec/rbenv-version-name index 90609d7f..5150989a 100755 --- a/libexec/rbenv-version-name +++ b/libexec/rbenv-version-name @@ -8,6 +8,13 @@ if [ -z "$RBENV_VERSION" ]; then RBENV_VERSION="$(rbenv-version-file-read "$RBENV_VERSION_FILE" || true)" fi +OLDIFS="$IFS" +IFS=$'\n' scripts=(`rbenv-hooks version-name`) +IFS="$OLDIFS" +for script in "${scripts[@]}"; do + source "$script" +done + if [ -z "$RBENV_VERSION" ] || [ "$RBENV_VERSION" = "system" ]; then echo "system" exit diff --git a/libexec/rbenv-version-origin b/libexec/rbenv-version-origin index ae7abf9c..3f1d4f03 100755 --- a/libexec/rbenv-version-origin +++ b/libexec/rbenv-version-origin @@ -3,7 +3,18 @@ set -e [ -n "$RBENV_DEBUG" ] && set -x -if [ -n "$RBENV_VERSION" ]; then +unset RBENV_VERSION_ORIGIN + +OLDIFS="$IFS" +IFS=$'\n' scripts=(`rbenv-hooks version-origin`) +IFS="$OLDIFS" +for script in "${scripts[@]}"; do + source "$script" +done + +if [ -n "$RBENV_VERSION_ORIGIN" ]; then + echo "$RBENV_VERSION_ORIGIN" +elif [ -n "$RBENV_VERSION" ]; then echo "RBENV_VERSION environment variable" else rbenv-version-file diff --git a/test/version-name.bats b/test/version-name.bats index 8d61ac55..82e1b2d0 100644 --- a/test/version-name.bats +++ b/test/version-name.bats @@ -22,6 +22,19 @@ setup() { assert_success "system" } +@test "RBENV_VERSION can be overridden by hook" { + create_version "1.8.7" + create_version "1.9.3" + + mkdir -p "${RBENV_ROOT}/rbenv.d/version-name" + cat > "${RBENV_ROOT}/rbenv.d/version-name/test.bash" < "${RBENV_ROOT}/rbenv.d/version-origin/test.bash" <