mirror of
https://github.com/pyenv/pyenv.git
synced 2024-11-30 07:24:24 -05:00
rbenv shell: properly declare global variables for zsh (#1566)
With zsh `setopt warn_create_global` the "shell" command used to cause a warning message: scalar parameter RBENV_VERSION_OLD created globally in function rbenv. By using `typeset -g` specifically for zsh, this warning goes away.
This commit is contained in:
parent
e8b7a27ee6
commit
f2ac882579
2 changed files with 36 additions and 0 deletions
|
@ -48,6 +48,10 @@ if [ "$version" = "--unset" ]; then
|
|||
echo 'set -gu RBENV_VERSION_OLD "$RBENV_VERSION"'
|
||||
echo "set -e RBENV_VERSION"
|
||||
;;
|
||||
zsh )
|
||||
echo "typeset -g RBENV_VERSION_OLD=\"\${RBENV_VERSION-}\""
|
||||
echo "unset RBENV_VERSION"
|
||||
;;
|
||||
* )
|
||||
echo 'RBENV_VERSION_OLD="${RBENV_VERSION-}"'
|
||||
echo "unset RBENV_VERSION"
|
||||
|
@ -74,6 +78,24 @@ else
|
|||
echo "rbenv: RBENV_VERSION_OLD is not set" >&2
|
||||
false
|
||||
end
|
||||
EOS
|
||||
;;
|
||||
zsh )
|
||||
cat <<EOS
|
||||
if [ -n "\${RBENV_VERSION_OLD+x}" ]; then
|
||||
if [ -n "\$RBENV_VERSION_OLD" ]; then
|
||||
local RBENV_VERSION_OLD_="\$RBENV_VERSION"
|
||||
export RBENV_VERSION="\$RBENV_VERSION_OLD"
|
||||
RBENV_VERSION_OLD="\$RBENV_VERSION_OLD_"
|
||||
unset RBENV_VERSION_OLD_
|
||||
else
|
||||
typeset -g RBENV_VERSION_OLD="\$RBENV_VERSION"
|
||||
unset RBENV_VERSION
|
||||
fi
|
||||
else
|
||||
echo "rbenv: RBENV_VERSION_OLD is not set" >&2
|
||||
false
|
||||
fi
|
||||
EOS
|
||||
;;
|
||||
* )
|
||||
|
@ -106,6 +128,10 @@ if rbenv-prefix "$version" >/dev/null; then
|
|||
echo 'set -gu RBENV_VERSION_OLD "$RBENV_VERSION"'
|
||||
echo "set -gx RBENV_VERSION \"$version\""
|
||||
;;
|
||||
zsh )
|
||||
echo "typeset -g RBENV_VERSION_OLD=\"\${RBENV_VERSION-}\""
|
||||
echo "export RBENV_VERSION=\"$version\""
|
||||
;;
|
||||
* )
|
||||
echo 'RBENV_VERSION_OLD="${RBENV_VERSION-}"'
|
||||
echo "export RBENV_VERSION=\"$version\""
|
||||
|
|
|
@ -80,6 +80,16 @@ export RBENV_VERSION="1.2.3"
|
|||
OUT
|
||||
}
|
||||
|
||||
@test "shell change version (zsh)" {
|
||||
mkdir -p "${RBENV_ROOT}/versions/1.2.3"
|
||||
RBENV_SHELL=zsh run rbenv-sh-shell 1.2.3
|
||||
assert_success
|
||||
assert_output <<OUT
|
||||
typeset -g RBENV_VERSION_OLD="\${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
|
||||
|
|
Loading…
Reference in a new issue