mirror of
https://github.com/pyenv/pyenv.git
synced 2025-01-22 23:11:15 +00:00
6a912bf104
`rbenv shell -` allows you to switch to the previously activated ruby version. Similar to `cd -` or `git checkout -`. This tries to implement `rbenv shell -` as proposed in #854. However, adding support seemed to break the "shell change version" test. I'm not very good at Bash programming, can someone tell me what is wrong with what I'm doing? I'd like to add a bit more functionality to this, but I'm really just cargo cult programming Bash. Thank you! fix tests
89 lines
2 KiB
Bash
Executable file
89 lines
2 KiB
Bash
Executable file
#!/usr/bin/env bash
|
|
#
|
|
# 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'
|
|
# environment variable in your shell. This version overrides local
|
|
# application-specific versions and the global version.
|
|
#
|
|
# <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.
|
|
|
|
set -e
|
|
[ -n "$RBENV_DEBUG" ] && set -x
|
|
|
|
# Provide rbenv completions
|
|
if [ "$1" = "--complete" ]; then
|
|
echo --unset
|
|
echo system
|
|
exec rbenv-versions --bare
|
|
fi
|
|
|
|
version="$1"
|
|
shell="$(basename "${RBENV_SHELL:-$SHELL}")"
|
|
|
|
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
|
|
case "$shell" in
|
|
fish )
|
|
echo "set -e OLD_RBENV_VERSION"
|
|
echo "set -e RBENV_VERSION"
|
|
;;
|
|
* )
|
|
echo "unset OLD_RBENV_VERSION"
|
|
echo "unset RBENV_VERSION"
|
|
;;
|
|
esac
|
|
exit
|
|
fi
|
|
|
|
if [ "$version" = "-" ]; then
|
|
if [ -z "$OLD_RBENV_VERSION" ]; then
|
|
echo "rbenv: OLD_RBENV_VERSION not set" >&2
|
|
exit 1;
|
|
fi
|
|
case "$shell" in
|
|
fish )
|
|
rbenv_version=$RBENV_VERSION
|
|
echo "set -e OLD_RBENV_VERSION \"$rbenv_version\""
|
|
echo "set -e RBENV_VERSION \"$OLD_RBENV_VERSION\""
|
|
;;
|
|
* )
|
|
rbenv_version=$RBENV_VERSION
|
|
echo "export OLD_RBENV_VERSION=\"$rbenv_version\""
|
|
echo "export RBENV_VERSION=\"$OLD_RBENV_VERSION\""
|
|
;;
|
|
esac
|
|
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 )
|
|
echo "setenv RBENV_VERSION \"${version}\""
|
|
;;
|
|
* )
|
|
echo "export OLD_RBENV_VERSION=\"$RBENV_VERSION\""
|
|
echo "export RBENV_VERSION=\"${version}\""
|
|
;;
|
|
esac
|
|
fi
|
|
else
|
|
echo "false"
|
|
exit 1
|
|
fi
|