Passing return value from executed command.

This commit is contained in:
Bartosz Janda
2015-10-14 21:18:09 +02:00
parent 6a6947659a
commit f657fad926
2 changed files with 15 additions and 5 deletions

View File

@@ -77,11 +77,12 @@ fish )
cat <<EOS cat <<EOS
function _pyenv_virtualenv_hook --on-event fish_prompt; function _pyenv_virtualenv_hook --on-event fish_prompt;
set -l PYENV_PREFIX (pyenv prefix 2>/dev/null; or true) set -l PYENV_PREFIX (pyenv prefix 2>/dev/null; or true)
set -l ret \$status
if [ -n "\$PYENV_ACTIVATE" ] if [ -n "\$PYENV_ACTIVATE" ]
if [ (pyenv version-name 2>/dev/null; or true) = "system" ] if [ (pyenv version-name 2>/dev/null; or true) = "system" ]
pyenv deactivate --no-error --verbose pyenv deactivate --no-error --verbose
set -e PYENV_DEACTIVATE set -e PYENV_DEACTIVATE
return 0 return \$ret
end end
if [ "\$PYENV_ACTIVATE" != "\$PYENV_PREFIX" ] if [ "\$PYENV_ACTIVATE" != "\$PYENV_PREFIX" ]
if pyenv deactivate --no-error --verbose if pyenv deactivate --no-error --verbose
@@ -96,6 +97,7 @@ function _pyenv_virtualenv_hook --on-event fish_prompt;
pyenv activate --no-error --verbose; or true pyenv activate --no-error --verbose; or true
end end
end end
return \$ret
end end
EOS EOS
;; ;;
@@ -113,11 +115,12 @@ esac
if [[ "$shell" != "fish" ]]; then if [[ "$shell" != "fish" ]]; then
cat <<EOS cat <<EOS
local ret=\$?
if [ -n "\$PYENV_ACTIVATE" ]; then if [ -n "\$PYENV_ACTIVATE" ]; then
if [ "\$(pyenv version-name 2>/dev/null || true)" = "system" ]; then if [ "\$(pyenv version-name 2>/dev/null || true)" = "system" ]; then
eval "\$(pyenv sh-deactivate --no-error --verbose)" eval "\$(pyenv sh-deactivate --no-error --verbose)"
unset PYENV_DEACTIVATE unset PYENV_DEACTIVATE
return 0 return \$ret
fi fi
if [ "\$PYENV_ACTIVATE" != "\$(pyenv prefix 2>/dev/null || true)" ]; then if [ "\$PYENV_ACTIVATE" != "\$(pyenv prefix 2>/dev/null || true)" ]; then
if eval "\$(pyenv sh-deactivate --no-error --verbose)"; then if eval "\$(pyenv sh-deactivate --no-error --verbose)"; then
@@ -132,6 +135,7 @@ if [[ "$shell" != "fish" ]]; then
eval "\$(pyenv sh-activate --no-error --verbose)" || true eval "\$(pyenv sh-activate --no-error --verbose)" || true
fi fi
fi fi
return \$ret
}; };
EOS EOS

View File

@@ -51,11 +51,12 @@ load test_helper
assert_output <<EOS assert_output <<EOS
export PYENV_VIRTUALENV_INIT=1; export PYENV_VIRTUALENV_INIT=1;
_pyenv_virtualenv_hook() { _pyenv_virtualenv_hook() {
local ret=\$?
if [ -n "\$PYENV_ACTIVATE" ]; then if [ -n "\$PYENV_ACTIVATE" ]; then
if [ "\$(pyenv version-name 2>/dev/null || true)" = "system" ]; then if [ "\$(pyenv version-name 2>/dev/null || true)" = "system" ]; then
eval "\$(pyenv sh-deactivate --no-error --verbose)" eval "\$(pyenv sh-deactivate --no-error --verbose)"
unset PYENV_DEACTIVATE unset PYENV_DEACTIVATE
return 0 return \$ret
fi fi
if [ "\$PYENV_ACTIVATE" != "\$(pyenv prefix 2>/dev/null || true)" ]; then if [ "\$PYENV_ACTIVATE" != "\$(pyenv prefix 2>/dev/null || true)" ]; then
if eval "\$(pyenv sh-deactivate --no-error --verbose)"; then if eval "\$(pyenv sh-deactivate --no-error --verbose)"; then
@@ -70,6 +71,7 @@ _pyenv_virtualenv_hook() {
eval "\$(pyenv sh-activate --no-error --verbose)" || true eval "\$(pyenv sh-activate --no-error --verbose)" || true
fi fi
fi fi
return \$ret
}; };
if ! [[ "\$PROMPT_COMMAND" =~ _pyenv_virtualenv_hook ]]; then if ! [[ "\$PROMPT_COMMAND" =~ _pyenv_virtualenv_hook ]]; then
PROMPT_COMMAND="_pyenv_virtualenv_hook;\$PROMPT_COMMAND"; PROMPT_COMMAND="_pyenv_virtualenv_hook;\$PROMPT_COMMAND";
@@ -84,11 +86,12 @@ EOS
setenv PYENV_VIRTUALENV_INIT 1; setenv PYENV_VIRTUALENV_INIT 1;
function _pyenv_virtualenv_hook --on-event fish_prompt; function _pyenv_virtualenv_hook --on-event fish_prompt;
set -l PYENV_PREFIX (pyenv prefix 2>/dev/null; or true) set -l PYENV_PREFIX (pyenv prefix 2>/dev/null; or true)
set -l ret \$status
if [ -n "\$PYENV_ACTIVATE" ] if [ -n "\$PYENV_ACTIVATE" ]
if [ (pyenv version-name 2>/dev/null; or true) = "system" ] if [ (pyenv version-name 2>/dev/null; or true) = "system" ]
pyenv deactivate --no-error --verbose pyenv deactivate --no-error --verbose
set -e PYENV_DEACTIVATE set -e PYENV_DEACTIVATE
return 0 return \$ret
end end
if [ "\$PYENV_ACTIVATE" != "\$PYENV_PREFIX" ] if [ "\$PYENV_ACTIVATE" != "\$PYENV_PREFIX" ]
if pyenv deactivate --no-error --verbose if pyenv deactivate --no-error --verbose
@@ -103,6 +106,7 @@ function _pyenv_virtualenv_hook --on-event fish_prompt;
pyenv activate --no-error --verbose; or true pyenv activate --no-error --verbose; or true
end end
end end
return \$ret
end end
EOS EOS
} }
@@ -113,11 +117,12 @@ EOS
assert_output <<EOS assert_output <<EOS
export PYENV_VIRTUALENV_INIT=1; export PYENV_VIRTUALENV_INIT=1;
_pyenv_virtualenv_hook() { _pyenv_virtualenv_hook() {
local ret=\$?
if [ -n "\$PYENV_ACTIVATE" ]; then if [ -n "\$PYENV_ACTIVATE" ]; then
if [ "\$(pyenv version-name 2>/dev/null || true)" = "system" ]; then if [ "\$(pyenv version-name 2>/dev/null || true)" = "system" ]; then
eval "\$(pyenv sh-deactivate --no-error --verbose)" eval "\$(pyenv sh-deactivate --no-error --verbose)"
unset PYENV_DEACTIVATE unset PYENV_DEACTIVATE
return 0 return \$ret
fi fi
if [ "\$PYENV_ACTIVATE" != "\$(pyenv prefix 2>/dev/null || true)" ]; then if [ "\$PYENV_ACTIVATE" != "\$(pyenv prefix 2>/dev/null || true)" ]; then
if eval "\$(pyenv sh-deactivate --no-error --verbose)"; then if eval "\$(pyenv sh-deactivate --no-error --verbose)"; then
@@ -132,6 +137,7 @@ _pyenv_virtualenv_hook() {
eval "\$(pyenv sh-activate --no-error --verbose)" || true eval "\$(pyenv sh-activate --no-error --verbose)" || true
fi fi
fi fi
return \$ret
}; };
typeset -g -a precmd_functions typeset -g -a precmd_functions
if [[ -z \$precmd_functions[(r)_pyenv_virtualenv_hook] ]]; then if [[ -z \$precmd_functions[(r)_pyenv_virtualenv_hook] ]]; then