2011-09-10 20:45:22 -04:00
|
|
|
#!/usr/bin/env bash
|
2012-12-29 13:06:20 -05:00
|
|
|
#
|
|
|
|
# Summary: Set or show the shell-specific Ruby version
|
|
|
|
#
|
|
|
|
# Usage: rbenv shell <version>
|
2016-11-25 14:24:16 -05:00
|
|
|
# rbenv shell -
|
2012-12-29 13:06:20 -05:00
|
|
|
# rbenv shell --unset
|
|
|
|
#
|
|
|
|
# Sets a shell-specific Ruby version by setting the `RBENV_VERSION'
|
2013-01-03 11:00:10 -05:00
|
|
|
# environment variable in your shell. This version overrides local
|
|
|
|
# application-specific versions and the global version.
|
2012-12-29 13:06:20 -05:00
|
|
|
#
|
|
|
|
# <version> should be a string matching a Ruby version known to rbenv.
|
|
|
|
# The special version string `system' will use your default system Ruby.
|
|
|
|
# Run `rbenv versions' for a list of available Ruby versions.
|
2016-11-25 14:24:16 -05:00
|
|
|
#
|
|
|
|
# When `-` is passed instead of the version string, the previously set
|
|
|
|
# version will be restored. With `--unset`, the `RBENV_VERSION`
|
|
|
|
# environment variable gets unset, restoring the environment to the
|
|
|
|
# state before the first `rbenv shell` call.
|
2012-12-29 13:06:20 -05:00
|
|
|
|
2011-09-10 20:45:22 -04:00
|
|
|
set -e
|
2011-09-12 11:11:59 -04:00
|
|
|
[ -n "$RBENV_DEBUG" ] && set -x
|
2011-09-09 08:18:14 -04:00
|
|
|
|
2011-09-13 13:38:34 -04:00
|
|
|
# Provide rbenv completions
|
|
|
|
if [ "$1" = "--complete" ]; then
|
2011-09-13 14:12:04 -04:00
|
|
|
echo --unset
|
|
|
|
echo system
|
2011-09-13 13:38:34 -04:00
|
|
|
exec rbenv-versions --bare
|
|
|
|
fi
|
|
|
|
|
2011-09-10 20:45:22 -04:00
|
|
|
version="$1"
|
2013-09-28 12:43:39 -04:00
|
|
|
shell="$(basename "${RBENV_SHELL:-$SHELL}")"
|
2011-09-10 20:45:22 -04:00
|
|
|
|
|
|
|
if [ -z "$version" ]; then
|
|
|
|
if [ -z "$RBENV_VERSION" ]; then
|
|
|
|
echo "rbenv: no shell-specific version configured" >&2
|
|
|
|
exit 1
|
|
|
|
else
|
2016-11-25 14:24:16 -05:00
|
|
|
echo 'echo "$RBENV_VERSION"'
|
2011-09-10 20:45:22 -04:00
|
|
|
exit
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$version" = "--unset" ]; then
|
2013-08-15 10:01:13 -04:00
|
|
|
case "$shell" in
|
|
|
|
fish )
|
2016-12-19 17:21:45 -05:00
|
|
|
echo 'set -gu RBENV_VERSION_OLD "$RBENV_VERSION"'
|
2013-08-15 10:01:13 -04:00
|
|
|
echo "set -e RBENV_VERSION"
|
|
|
|
;;
|
|
|
|
* )
|
2016-12-19 17:21:45 -05:00
|
|
|
echo 'RBENV_VERSION_OLD="$RBENV_VERSION"'
|
2013-08-15 10:01:13 -04:00
|
|
|
echo "unset RBENV_VERSION"
|
|
|
|
;;
|
|
|
|
esac
|
2012-12-12 20:58:41 -05:00
|
|
|
exit
|
2011-09-09 08:18:14 -04:00
|
|
|
fi
|
|
|
|
|
2016-01-12 14:03:50 -05:00
|
|
|
if [ "$version" = "-" ]; then
|
2013-08-15 10:01:13 -04:00
|
|
|
case "$shell" in
|
|
|
|
fish )
|
2016-11-25 14:24:16 -05:00
|
|
|
cat <<EOS
|
2016-12-19 17:21:45 -05:00
|
|
|
if set -q RBENV_VERSION_OLD
|
|
|
|
if [ -n "\$RBENV_VERSION_OLD" ]
|
|
|
|
set RBENV_VERSION_OLD_ "\$RBENV_VERSION"
|
|
|
|
set -gx RBENV_VERSION "\$RBENV_VERSION_OLD"
|
|
|
|
set -gu RBENV_VERSION_OLD "\$RBENV_VERSION_OLD_"
|
|
|
|
set -e RBENV_VERSION_OLD_
|
2016-11-25 14:24:16 -05:00
|
|
|
else
|
2016-12-19 17:21:45 -05:00
|
|
|
set -gu RBENV_VERSION_OLD "\$RBENV_VERSION"
|
2016-11-25 14:24:16 -05:00
|
|
|
set -e RBENV_VERSION
|
|
|
|
end
|
|
|
|
else
|
2016-12-19 17:21:45 -05:00
|
|
|
echo "rbenv: RBENV_VERSION_OLD is not set" >&2
|
2016-11-25 14:24:16 -05:00
|
|
|
false
|
|
|
|
end
|
|
|
|
EOS
|
2013-08-15 10:01:13 -04:00
|
|
|
;;
|
|
|
|
* )
|
2016-11-25 14:24:16 -05:00
|
|
|
cat <<EOS
|
2016-12-19 17:21:45 -05:00
|
|
|
if [ -n "\${RBENV_VERSION_OLD+x}" ]; then
|
|
|
|
if [ -n "\$RBENV_VERSION_OLD" ]; then
|
|
|
|
RBENV_VERSION_OLD_="\$RBENV_VERSION"
|
|
|
|
export RBENV_VERSION="\$RBENV_VERSION_OLD"
|
|
|
|
RBENV_VERSION_OLD="\$RBENV_VERSION_OLD_"
|
|
|
|
unset RBENV_VERSION_OLD_
|
2016-11-25 14:24:16 -05:00
|
|
|
else
|
2016-12-19 17:21:45 -05:00
|
|
|
RBENV_VERSION_OLD="\$RBENV_VERSION"
|
2016-11-25 14:24:16 -05:00
|
|
|
unset RBENV_VERSION
|
|
|
|
fi
|
|
|
|
else
|
2016-12-19 17:21:45 -05:00
|
|
|
echo "rbenv: RBENV_VERSION_OLD is not set" >&2
|
2016-11-25 14:24:16 -05:00
|
|
|
false
|
|
|
|
fi
|
|
|
|
EOS
|
2013-08-15 10:01:13 -04:00
|
|
|
;;
|
|
|
|
esac
|
2016-01-12 14:03:50 -05:00
|
|
|
exit
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Make sure the specified version is installed.
|
|
|
|
if rbenv-prefix "$version" >/dev/null; then
|
|
|
|
if [ "$version" != "$RBENV_VERSION" ]; then
|
|
|
|
case "$shell" in
|
|
|
|
fish )
|
2016-12-19 17:21:45 -05:00
|
|
|
echo 'set -gu RBENV_VERSION_OLD "$RBENV_VERSION"'
|
2016-11-25 14:24:16 -05:00
|
|
|
echo "set -gx RBENV_VERSION \"$version\""
|
2016-01-12 14:03:50 -05:00
|
|
|
;;
|
|
|
|
* )
|
2016-12-19 17:21:45 -05:00
|
|
|
echo 'RBENV_VERSION_OLD="$RBENV_VERSION"'
|
2016-11-25 14:24:16 -05:00
|
|
|
echo "export RBENV_VERSION=\"$version\""
|
2016-01-12 14:03:50 -05:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
fi
|
2012-12-12 20:58:41 -05:00
|
|
|
else
|
2013-08-15 10:01:13 -04:00
|
|
|
echo "false"
|
2012-12-12 20:58:41 -05:00
|
|
|
exit 1
|
|
|
|
fi
|