2011-09-11 00:45:22 +00:00
|
|
|
#!/usr/bin/env bash
|
2012-12-29 18:06:20 +00:00
|
|
|
#
|
|
|
|
# Summary: Set or show the shell-specific Ruby version
|
|
|
|
#
|
|
|
|
# Usage: rbenv shell <version>
|
|
|
|
# rbenv shell --unset
|
|
|
|
#
|
|
|
|
# Sets a shell-specific Ruby version by setting the `RBENV_VERSION'
|
2013-01-03 16:00:10 +00:00
|
|
|
# environment variable in your shell. This version overrides local
|
|
|
|
# application-specific versions and the global version.
|
2012-12-29 18:06:20 +00: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.
|
|
|
|
|
2011-09-11 00:45:22 +00:00
|
|
|
set -e
|
2011-09-12 15:11:59 +00:00
|
|
|
[ -n "$RBENV_DEBUG" ] && set -x
|
2011-09-09 12:18:14 +00:00
|
|
|
|
2011-09-13 17:38:34 +00:00
|
|
|
# Provide rbenv completions
|
|
|
|
if [ "$1" = "--complete" ]; then
|
2011-09-13 18:12:04 +00:00
|
|
|
echo --unset
|
|
|
|
echo system
|
2011-09-13 17:38:34 +00:00
|
|
|
exec rbenv-versions --bare
|
|
|
|
fi
|
|
|
|
|
2011-09-11 00:45:22 +00:00
|
|
|
version="$1"
|
2013-08-15 14:01:13 +00:00
|
|
|
shell="$(basename "$SHELL")"
|
2011-09-11 00:45:22 +00:00
|
|
|
|
|
|
|
if [ -z "$version" ]; then
|
|
|
|
if [ -z "$RBENV_VERSION" ]; then
|
|
|
|
echo "rbenv: no shell-specific version configured" >&2
|
|
|
|
exit 1
|
|
|
|
else
|
|
|
|
echo "echo \"\$RBENV_VERSION\""
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$version" = "--unset" ]; then
|
2013-08-15 14:01:13 +00:00
|
|
|
case "$shell" in
|
|
|
|
fish )
|
|
|
|
echo "set -e RBENV_VERSION"
|
|
|
|
;;
|
|
|
|
* )
|
|
|
|
echo "unset RBENV_VERSION"
|
|
|
|
;;
|
|
|
|
esac
|
2012-12-13 01:58:41 +00:00
|
|
|
exit
|
2011-09-09 12:18:14 +00:00
|
|
|
fi
|
|
|
|
|
2011-09-11 00:45:22 +00:00
|
|
|
# Make sure the specified version is installed.
|
2012-12-13 01:58:41 +00:00
|
|
|
if rbenv-prefix "$version" >/dev/null; then
|
2013-08-15 14:01:13 +00:00
|
|
|
case "$shell" in
|
|
|
|
fish )
|
|
|
|
echo "setenv RBENV_VERSION \"${version}\""
|
|
|
|
;;
|
|
|
|
* )
|
|
|
|
echo "export RBENV_VERSION=\"${version}\""
|
|
|
|
;;
|
|
|
|
esac
|
2012-12-13 01:58:41 +00:00
|
|
|
else
|
2013-08-15 14:01:13 +00:00
|
|
|
echo "false"
|
2012-12-13 01:58:41 +00:00
|
|
|
exit 1
|
|
|
|
fi
|