michael@0: # This file must be used with "source bin/activate.fish" *from fish* (http://fishshell.com) michael@0: # you cannot run it directly michael@0: michael@0: function deactivate -d "Exit virtualenv and return to normal shell environment" michael@0: # reset old environment variables michael@0: if test -n "$_OLD_VIRTUAL_PATH" michael@0: set -gx PATH $_OLD_VIRTUAL_PATH michael@0: set -e _OLD_VIRTUAL_PATH michael@0: end michael@0: if test -n "$_OLD_VIRTUAL_PYTHONHOME" michael@0: set -gx PYTHONHOME $_OLD_VIRTUAL_PYTHONHOME michael@0: set -e _OLD_VIRTUAL_PYTHONHOME michael@0: end michael@0: michael@0: if test -n "$_OLD_FISH_PROMPT_OVERRIDE" michael@0: # set an empty local fish_function_path, so fish_prompt doesn't automatically reload michael@0: set -l fish_function_path michael@0: # erase the virtualenv's fish_prompt function, and restore the original michael@0: functions -e fish_prompt michael@0: functions -c _old_fish_prompt fish_prompt michael@0: functions -e _old_fish_prompt michael@0: set -e _OLD_FISH_PROMPT_OVERRIDE michael@0: end michael@0: michael@0: set -e VIRTUAL_ENV michael@0: if test "$argv[1]" != "nondestructive" michael@0: # Self destruct! michael@0: functions -e deactivate michael@0: end michael@0: end michael@0: michael@0: # unset irrelevant variables michael@0: deactivate nondestructive michael@0: michael@0: set -gx VIRTUAL_ENV "__VIRTUAL_ENV__" michael@0: michael@0: set -gx _OLD_VIRTUAL_PATH $PATH michael@0: set -gx PATH "$VIRTUAL_ENV/__BIN_NAME__" $PATH michael@0: michael@0: # unset PYTHONHOME if set michael@0: if set -q PYTHONHOME michael@0: set -gx _OLD_VIRTUAL_PYTHONHOME $PYTHONHOME michael@0: set -e PYTHONHOME michael@0: end michael@0: michael@0: if test -z "$VIRTUAL_ENV_DISABLE_PROMPT" michael@0: # fish uses a function instead of an env var to generate the prompt. michael@0: michael@0: # copy the current fish_prompt function as the function _old_fish_prompt michael@0: functions -c fish_prompt _old_fish_prompt michael@0: michael@0: # with the original prompt function copied, we can override with our own. michael@0: function fish_prompt michael@0: # Prompt override? michael@0: if test -n "__VIRTUAL_PROMPT__" michael@0: printf "%s%s" "__VIRTUAL_PROMPT__" (set_color normal) michael@0: _old_fish_prompt michael@0: return michael@0: end michael@0: # ...Otherwise, prepend env michael@0: set -l _checkbase (basename "$VIRTUAL_ENV") michael@0: if test $_checkbase = "__" michael@0: # special case for Aspen magic directories michael@0: # see http://www.zetadev.com/software/aspen/ michael@0: printf "%s[%s]%s " (set_color -b blue white) (basename (dirname "$VIRTUAL_ENV")) (set_color normal) michael@0: _old_fish_prompt michael@0: else michael@0: printf "%s(%s)%s" (set_color -b blue white) (basename "$VIRTUAL_ENV") (set_color normal) michael@0: _old_fish_prompt michael@0: end michael@0: end michael@0: michael@0: set -gx _OLD_FISH_PROMPT_OVERRIDE "$VIRTUAL_ENV" michael@0: end