mirror of
https://github.com/pyenv/pyenv.git
synced 2024-12-23 00:20:47 +00:00
258e4413b1
Expose a `version-name` hook. It is invoked *after* the traditional `RBENV_VERSION` lookup. Which means hook scripts can interrogate `$RBENV_VERSION_FILE` and/or `$RBENV_VERSION` (or use the executables). The hooks are then run, giving plugins a chance to alter `RBENV_VERSION`. Once the hooks have run, we now have (in `$RBENV_VERSION`) the actual version we want to use (or it's empty which defaults to `system` per normal). Lastly, the same logic remains for checking if the version exists, or trimming the `ruby-` prefix. Prime example: the ruby-bundler-ruby-version plugin can select a ruby by using the `ruby` directive from the `Gemfile` if a local `.ruby-version` doesn't exist.
35 lines
803 B
Bash
Executable file
35 lines
803 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
|
|
|
|
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
|
|
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" >&2
|
|
exit 1
|
|
fi
|