1# This file must be used with "source <venv>/bin/activate.fish" *from fish* 2# (https://fishshell.com/); you cannot run it directly. 3 4function deactivate -d "Exit virtual environment and return to normal shell environment" 5 # reset old environment variables 6 if test -n "$_OLD_VIRTUAL_PATH" 7 set -gx PATH $_OLD_VIRTUAL_PATH 8 set -e _OLD_VIRTUAL_PATH 9 end 10 if test -n "$_OLD_VIRTUAL_PYTHONHOME" 11 set -gx PYTHONHOME $_OLD_VIRTUAL_PYTHONHOME 12 set -e _OLD_VIRTUAL_PYTHONHOME 13 end 14 15 if test -n "$_OLD_FISH_PROMPT_OVERRIDE" 16 functions -e fish_prompt 17 set -e _OLD_FISH_PROMPT_OVERRIDE 18 functions -c _old_fish_prompt fish_prompt 19 functions -e _old_fish_prompt 20 end 21 22 set -e VIRTUAL_ENV 23 set -e VIRTUAL_ENV_PROMPT 24 if test "$argv[1]" != "nondestructive" 25 # Self-destruct! 26 functions -e deactivate 27 end 28end 29 30# Unset irrelevant variables. 31deactivate nondestructive 32 33set -gx VIRTUAL_ENV "__VENV_DIR__" 34 35set -gx _OLD_VIRTUAL_PATH $PATH 36set -gx PATH "$VIRTUAL_ENV/__VENV_BIN_NAME__" $PATH 37 38# Unset PYTHONHOME if set. 39if set -q PYTHONHOME 40 set -gx _OLD_VIRTUAL_PYTHONHOME $PYTHONHOME 41 set -e PYTHONHOME 42end 43 44if test -z "$VIRTUAL_ENV_DISABLE_PROMPT" 45 # fish uses a function instead of an env var to generate the prompt. 46 47 # Save the current fish_prompt function as the function _old_fish_prompt. 48 functions -c fish_prompt _old_fish_prompt 49 50 # With the original prompt function renamed, we can override with our own. 51 function fish_prompt 52 # Save the return status of the last command. 53 set -l old_status $status 54 55 # Output the venv prompt; color taken from the blue of the Python logo. 56 printf "%s%s%s" (set_color 4B8BBE) "__VENV_PROMPT__" (set_color normal) 57 58 # Restore the return status of the previous command. 59 echo "exit $old_status" | . 60 # Output the original/"old" prompt. 61 _old_fish_prompt 62 end 63 64 set -gx _OLD_FISH_PROMPT_OVERRIDE "$VIRTUAL_ENV" 65 set -gx VIRTUAL_ENV_PROMPT "__VENV_PROMPT__" 66end 67