Add support for RBENV_VERSION=system

This commit is contained in:
Sam Stephenson 2011-08-03 08:39:56 -05:00
parent 4668a2e2ed
commit e0e2d93639
3 changed files with 39 additions and 1 deletions

View file

@ -6,6 +6,12 @@ elif [ -z "$RBENV_VERSION" ]; then
RBENV_VERSION="$(rbenv-version)"
fi
if [ "$RBENV_VERSION" = "system" ]; then
RUBY_PATH="$(rbenv-which ruby)"
echo "${RUBY_PATH%/*}"
exit
fi
RBENV_PREFIX_PATH="${HOME}/.rbenv/versions/${RBENV_VERSION}"
if [ ! -d "$RBENV_PREFIX_PATH" ]; then
echo "rbenv: version \`${RBENV_VERSION}' not installed" >&2

View file

@ -36,6 +36,11 @@ if [ -z "$RBENV_VERSION" ]; then
fi
fi
if [ "$RBENV_VERSION" = "system" ]; then
echo "$RBENV_VERSION"
exit
fi
RBENV_VERSION_PATH="${HOME}/.rbenv/versions/${RBENV_VERSION}"
if [ -d "$RBENV_VERSION_PATH" ]; then

View file

@ -1,8 +1,35 @@
#!/usr/bin/env bash -e
expand_path() {
local cwd="$(pwd)"
cd "$1"
pwd
cd "$cwd"
}
remove_from_path() {
local path_to_remove="$(expand_path "$1")"
local result=""
for path in ${PATH//:/$'\n'}; do
path="$(expand_path "$path" || true)"
if [ "$path" != "$path_to_remove" ]; then
result="${result}${path}:"
fi
done
echo "${result%:}"
}
RBENV_VERSION="$(rbenv-version)"
RBENV_COMMAND="$1"
if [ "$RBENV_VERSION" = "system" ]; then
PATH="$(remove_from_path "${HOME}/.rbenv/shims")"
RBENV_COMMAND_PATH="$(command -v "$RBENV_COMMAND")"
else
RBENV_COMMAND_PATH="${HOME}/.rbenv/versions/${RBENV_VERSION}/bin/${RBENV_COMMAND}"
fi
if [ -x "$RBENV_COMMAND_PATH" ]; then
echo "$RBENV_COMMAND_PATH"