2011-08-12 09:33:45 +00:00
|
|
|
#!/usr/bin/env bash
|
2012-12-30 04:05:04 +00:00
|
|
|
# Summary: Explain how the current Ruby version is set
|
2011-08-12 09:33:45 +00:00
|
|
|
set -e
|
2011-09-12 15:11:59 +00:00
|
|
|
[ -n "$RBENV_DEBUG" ] && set -x
|
2011-08-09 20:41:35 +00:00
|
|
|
|
2015-12-23 16:26:53 +00:00
|
|
|
unset RBENV_VERSION_ORIGIN
|
|
|
|
|
create hook: version-origin
Expose a `version-origin` hook.
It is invoked *before* the traditional `rbenv-version-file` lookup. Because `version-origin` is traditionally run immediately after `version-name`, then any plugin hooks that alter `version-name` would have done so. Thus, running `version-origin` prior to printing the origin gives those plugins a chance to alter the `version-origin` to match.
If any of the hooks set `$RBENV_VERSION_ORIGIN`, then it is used as the return value. Otherwise, the existing logic continues to return "environment variable" or "filename" as appropriate.
This change, in conjunction with the `version-name` hook, makes a clean seam by which plugins can inject their own ruby version setting logic. Using this seam, as opposed to altering `$RBENV_COMMAND_PATH` from the `which` hook, means that the version name and origin are set more reliably and so `version`, `version-name`, `version-origin` and `which` all work as expected. Indeed, even PS1 works now.
2015-05-28 03:29:11 +00:00
|
|
|
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
|
2011-08-09 20:41:35 +00:00
|
|
|
echo "RBENV_VERSION environment variable"
|
2011-08-18 19:11:40 +00:00
|
|
|
else
|
|
|
|
rbenv-version-file
|
2011-08-09 20:41:35 +00:00
|
|
|
fi
|