Fixes #25671: Updated prompt handling in activate.fish.

This commit is contained in:
Vinay Sajip 2016-09-11 12:52:08 +01:00
parent b7665386bc
commit 8d82559ca7
1 changed files with 20 additions and 19 deletions

View File

@ -15,10 +15,7 @@ function deactivate -d "Exit virtualenv and return to normal shell environment"
if test -n "$_OLD_FISH_PROMPT_OVERRIDE" if test -n "$_OLD_FISH_PROMPT_OVERRIDE"
functions -e fish_prompt functions -e fish_prompt
set -e _OLD_FISH_PROMPT_OVERRIDE set -e _OLD_FISH_PROMPT_OVERRIDE
. ( begin functions -c _old_fish_prompt fish_prompt
printf "function fish_prompt\n\t#"
functions _old_fish_prompt
end | psub )
functions -e _old_fish_prompt functions -e _old_fish_prompt
end end
@ -47,28 +44,32 @@ if test -z "$VIRTUAL_ENV_DISABLE_PROMPT"
# fish uses a function instead of an env var to generate the prompt. # fish uses a function instead of an env var to generate the prompt.
# save the current fish_prompt function as the function _old_fish_prompt # save the current fish_prompt function as the function _old_fish_prompt
. ( begin functions -c fish_prompt _old_fish_prompt
printf "function _old_fish_prompt\n\t#"
functions fish_prompt
end | psub )
# with the original prompt function renamed, we can override with our own. # with the original prompt function renamed, we can override with our own.
function fish_prompt function fish_prompt
# Save the return status of the last command
set -l old_status $status
# Prompt override? # Prompt override?
if test -n "__VENV_PROMPT__" if test -n "__VENV_PROMPT__"
printf "%s%s%s" "__VENV_PROMPT__" (set_color normal) (_old_fish_prompt) printf "%s%s" "__VENV_PROMPT__" (set_color normal)
return else
end
# ...Otherwise, prepend env # ...Otherwise, prepend env
set -l _checkbase (basename "$VIRTUAL_ENV") set -l _checkbase (basename "$VIRTUAL_ENV")
if test $_checkbase = "__" if test $_checkbase = "__"
# special case for Aspen magic directories # special case for Aspen magic directories
# see http://www.zetadev.com/software/aspen/ # see http://www.zetadev.com/software/aspen/
printf "%s[%s]%s %s" (set_color -b blue white) (basename (dirname "$VIRTUAL_ENV")) (set_color normal) (_old_fish_prompt) printf "%s[%s]%s " (set_color -b blue white) (basename (dirname "$VIRTUAL_ENV")) (set_color normal)
else else
printf "%s(%s)%s%s" (set_color -b blue white) (basename "$VIRTUAL_ENV") (set_color normal) (_old_fish_prompt) printf "%s(%s)%s" (set_color -b blue white) (basename "$VIRTUAL_ENV") (set_color normal)
end end
end end
# Restore the return status of the previous command.
echo "exit $old_status" | .
_old_fish_prompt
end
set -gx _OLD_FISH_PROMPT_OVERRIDE "$VIRTUAL_ENV" set -gx _OLD_FISH_PROMPT_OVERRIDE "$VIRTUAL_ENV"
end end