python/virtualenv/virtualenv_embedded/activate.fish

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 # This file must be used with "source bin/activate.fish" *from fish* (http://fishshell.com)
     2 # you cannot run it directly
     4 function deactivate  -d "Exit virtualenv 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
    15     if test -n "$_OLD_FISH_PROMPT_OVERRIDE"
    16         # set an empty local fish_function_path, so fish_prompt doesn't automatically reload
    17         set -l fish_function_path
    18         # erase the virtualenv's fish_prompt function, and restore the original
    19         functions -e fish_prompt
    20         functions -c _old_fish_prompt fish_prompt
    21         functions -e _old_fish_prompt
    22         set -e _OLD_FISH_PROMPT_OVERRIDE
    23     end
    25     set -e VIRTUAL_ENV
    26     if test "$argv[1]" != "nondestructive"
    27         # Self destruct!
    28         functions -e deactivate
    29     end
    30 end
    32 # unset irrelevant variables
    33 deactivate nondestructive
    35 set -gx VIRTUAL_ENV "__VIRTUAL_ENV__"
    37 set -gx _OLD_VIRTUAL_PATH $PATH
    38 set -gx PATH "$VIRTUAL_ENV/__BIN_NAME__" $PATH
    40 # unset PYTHONHOME if set
    41 if set -q PYTHONHOME
    42     set -gx _OLD_VIRTUAL_PYTHONHOME $PYTHONHOME
    43     set -e PYTHONHOME
    44 end
    46 if test -z "$VIRTUAL_ENV_DISABLE_PROMPT"
    47     # fish uses a function instead of an env var to generate the prompt.
    49     # copy the current fish_prompt function as the function _old_fish_prompt
    50     functions -c fish_prompt _old_fish_prompt
    52     # with the original prompt function copied, we can override with our own.
    53     function fish_prompt
    54         # Prompt override?
    55         if test -n "__VIRTUAL_PROMPT__"
    56             printf "%s%s" "__VIRTUAL_PROMPT__" (set_color normal)
    57             _old_fish_prompt
    58             return
    59         end
    60         # ...Otherwise, prepend env
    61         set -l _checkbase (basename "$VIRTUAL_ENV")
    62         if test $_checkbase = "__"
    63             # special case for Aspen magic directories
    64             # see http://www.zetadev.com/software/aspen/
    65             printf "%s[%s]%s " (set_color -b blue white) (basename (dirname "$VIRTUAL_ENV")) (set_color normal) 
    66             _old_fish_prompt
    67         else
    68             printf "%s(%s)%s" (set_color -b blue white) (basename "$VIRTUAL_ENV") (set_color normal)
    69             _old_fish_prompt
    70         end
    71     end 
    73     set -gx _OLD_FISH_PROMPT_OVERRIDE "$VIRTUAL_ENV"
    74 end

mercurial