mirror of
https://github.com/pyenv/pyenv.git
synced 2024-11-14 20:39:55 -05:00
Merge branch 'shell-undo'
This commit is contained in:
commit
2207c27cb4
2 changed files with 95 additions and 13 deletions
|
@ -3,6 +3,7 @@
|
|||
# Summary: Set or show the shell-specific Ruby version
|
||||
#
|
||||
# Usage: rbenv shell <version>
|
||||
# rbenv shell -
|
||||
# rbenv shell --unset
|
||||
#
|
||||
# Sets a shell-specific Ruby version by setting the `RBENV_VERSION'
|
||||
|
@ -12,6 +13,11 @@
|
|||
# <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.
|
||||
#
|
||||
# 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.
|
||||
|
||||
set -e
|
||||
[ -n "$RBENV_DEBUG" ] && set -x
|
||||
|
@ -31,7 +37,7 @@ if [ -z "$version" ]; then
|
|||
echo "rbenv: no shell-specific version configured" >&2
|
||||
exit 1
|
||||
else
|
||||
echo "echo \"\$RBENV_VERSION\""
|
||||
echo 'echo "$RBENV_VERSION"'
|
||||
exit
|
||||
fi
|
||||
fi
|
||||
|
@ -39,25 +45,73 @@ fi
|
|||
if [ "$version" = "--unset" ]; then
|
||||
case "$shell" in
|
||||
fish )
|
||||
echo 'set -gu OLD_RBENV_VERSION "$RBENV_VERSION"'
|
||||
echo "set -e RBENV_VERSION"
|
||||
;;
|
||||
* )
|
||||
echo 'OLD_RBENV_VERSION="$RBENV_VERSION"'
|
||||
echo "unset RBENV_VERSION"
|
||||
;;
|
||||
esac
|
||||
exit
|
||||
fi
|
||||
|
||||
if [ "$version" = "-" ]; then
|
||||
case "$shell" in
|
||||
fish )
|
||||
cat <<EOS
|
||||
if set -q OLD_RBENV_VERSION
|
||||
if [ -n "\$OLD_RBENV_VERSION" ]
|
||||
set OLD_RBENV_VERSION_ "\$RBENV_VERSION"
|
||||
set -gx RBENV_VERSION "\$OLD_RBENV_VERSION"
|
||||
set -gu OLD_RBENV_VERSION "\$OLD_RBENV_VERSION_"
|
||||
set -e OLD_RBENV_VERSION_
|
||||
else
|
||||
set -gu OLD_RBENV_VERSION "\$RBENV_VERSION"
|
||||
set -e RBENV_VERSION
|
||||
end
|
||||
else
|
||||
echo "rbenv: OLD_RBENV_VERSION is not set" >&2
|
||||
false
|
||||
end
|
||||
EOS
|
||||
;;
|
||||
* )
|
||||
cat <<EOS
|
||||
if [ -n "\${OLD_RBENV_VERSION+x}" ]; then
|
||||
if [ -n "\$OLD_RBENV_VERSION" ]; then
|
||||
OLD_RBENV_VERSION_="\$RBENV_VERSION"
|
||||
export RBENV_VERSION="\$OLD_RBENV_VERSION"
|
||||
OLD_RBENV_VERSION="\$OLD_RBENV_VERSION_"
|
||||
unset OLD_RBENV_VERSION_
|
||||
else
|
||||
OLD_RBENV_VERSION="\$RBENV_VERSION"
|
||||
unset RBENV_VERSION
|
||||
fi
|
||||
else
|
||||
echo "rbenv: OLD_RBENV_VERSION is not set" >&2
|
||||
false
|
||||
fi
|
||||
EOS
|
||||
;;
|
||||
esac
|
||||
exit
|
||||
fi
|
||||
|
||||
# Make sure the specified version is installed.
|
||||
if rbenv-prefix "$version" >/dev/null; then
|
||||
case "$shell" in
|
||||
fish )
|
||||
echo "setenv RBENV_VERSION \"${version}\""
|
||||
;;
|
||||
* )
|
||||
echo "export RBENV_VERSION=\"${version}\""
|
||||
;;
|
||||
esac
|
||||
if [ "$version" != "$RBENV_VERSION" ]; then
|
||||
case "$shell" in
|
||||
fish )
|
||||
echo 'set -gu OLD_RBENV_VERSION "$RBENV_VERSION"'
|
||||
echo "set -gx RBENV_VERSION \"$version\""
|
||||
;;
|
||||
* )
|
||||
echo 'OLD_RBENV_VERSION="$RBENV_VERSION"'
|
||||
echo "export RBENV_VERSION=\"$version\""
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
else
|
||||
echo "false"
|
||||
exit 1
|
||||
|
|
|
@ -20,14 +20,34 @@ load test_helper
|
|||
assert_success 'echo "$RBENV_VERSION"'
|
||||
}
|
||||
|
||||
@test "shell revert" {
|
||||
RBENV_SHELL=bash run rbenv-sh-shell -
|
||||
assert_success
|
||||
assert_line 0 'if [ -n "${OLD_RBENV_VERSION+x}" ]; then'
|
||||
}
|
||||
|
||||
@test "shell revert (fish)" {
|
||||
RBENV_SHELL=fish run rbenv-sh-shell -
|
||||
assert_success
|
||||
assert_line 0 'if set -q OLD_RBENV_VERSION'
|
||||
}
|
||||
|
||||
@test "shell unset" {
|
||||
RBENV_SHELL=bash run rbenv-sh-shell --unset
|
||||
assert_success "unset RBENV_VERSION"
|
||||
assert_success
|
||||
assert_output <<OUT
|
||||
OLD_RBENV_VERSION="\$RBENV_VERSION"
|
||||
unset RBENV_VERSION
|
||||
OUT
|
||||
}
|
||||
|
||||
@test "shell unset (fish)" {
|
||||
RBENV_SHELL=fish run rbenv-sh-shell --unset
|
||||
assert_success "set -e RBENV_VERSION"
|
||||
assert_success
|
||||
assert_output <<OUT
|
||||
set -gu OLD_RBENV_VERSION "\$RBENV_VERSION"
|
||||
set -e RBENV_VERSION
|
||||
OUT
|
||||
}
|
||||
|
||||
@test "shell change invalid version" {
|
||||
|
@ -42,11 +62,19 @@ SH
|
|||
@test "shell change version" {
|
||||
mkdir -p "${RBENV_ROOT}/versions/1.2.3"
|
||||
RBENV_SHELL=bash run rbenv-sh-shell 1.2.3
|
||||
assert_success 'export RBENV_VERSION="1.2.3"'
|
||||
assert_success
|
||||
assert_output <<OUT
|
||||
OLD_RBENV_VERSION="\$RBENV_VERSION"
|
||||
export RBENV_VERSION="1.2.3"
|
||||
OUT
|
||||
}
|
||||
|
||||
@test "shell change version (fish)" {
|
||||
mkdir -p "${RBENV_ROOT}/versions/1.2.3"
|
||||
RBENV_SHELL=fish run rbenv-sh-shell 1.2.3
|
||||
assert_success 'setenv RBENV_VERSION "1.2.3"'
|
||||
assert_success
|
||||
assert_output <<OUT
|
||||
set -gu OLD_RBENV_VERSION "\$RBENV_VERSION"
|
||||
set -gx RBENV_VERSION "1.2.3"
|
||||
OUT
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue