python/virtualenv/virtualenv_embedded/activate.fish

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/python/virtualenv/virtualenv_embedded/activate.fish	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,74 @@
     1.4 +# This file must be used with "source bin/activate.fish" *from fish* (http://fishshell.com)
     1.5 +# you cannot run it directly
     1.6 +
     1.7 +function deactivate  -d "Exit virtualenv and return to normal shell environment"
     1.8 +    # reset old environment variables
     1.9 +    if test -n "$_OLD_VIRTUAL_PATH" 
    1.10 +        set -gx PATH $_OLD_VIRTUAL_PATH
    1.11 +        set -e _OLD_VIRTUAL_PATH
    1.12 +    end
    1.13 +    if test -n "$_OLD_VIRTUAL_PYTHONHOME"
    1.14 +        set -gx PYTHONHOME $_OLD_VIRTUAL_PYTHONHOME
    1.15 +        set -e _OLD_VIRTUAL_PYTHONHOME
    1.16 +    end
    1.17 +    
    1.18 +    if test -n "$_OLD_FISH_PROMPT_OVERRIDE"
    1.19 +        # set an empty local fish_function_path, so fish_prompt doesn't automatically reload
    1.20 +        set -l fish_function_path
    1.21 +        # erase the virtualenv's fish_prompt function, and restore the original
    1.22 +        functions -e fish_prompt
    1.23 +        functions -c _old_fish_prompt fish_prompt
    1.24 +        functions -e _old_fish_prompt
    1.25 +        set -e _OLD_FISH_PROMPT_OVERRIDE
    1.26 +    end
    1.27 +    
    1.28 +    set -e VIRTUAL_ENV
    1.29 +    if test "$argv[1]" != "nondestructive"
    1.30 +        # Self destruct!
    1.31 +        functions -e deactivate
    1.32 +    end
    1.33 +end
    1.34 +
    1.35 +# unset irrelevant variables
    1.36 +deactivate nondestructive
    1.37 +
    1.38 +set -gx VIRTUAL_ENV "__VIRTUAL_ENV__"
    1.39 +
    1.40 +set -gx _OLD_VIRTUAL_PATH $PATH
    1.41 +set -gx PATH "$VIRTUAL_ENV/__BIN_NAME__" $PATH
    1.42 +
    1.43 +# unset PYTHONHOME if set
    1.44 +if set -q PYTHONHOME
    1.45 +    set -gx _OLD_VIRTUAL_PYTHONHOME $PYTHONHOME
    1.46 +    set -e PYTHONHOME
    1.47 +end
    1.48 +
    1.49 +if test -z "$VIRTUAL_ENV_DISABLE_PROMPT"
    1.50 +    # fish uses a function instead of an env var to generate the prompt.
    1.51 +    
    1.52 +    # copy the current fish_prompt function as the function _old_fish_prompt
    1.53 +    functions -c fish_prompt _old_fish_prompt
    1.54 +    
    1.55 +    # with the original prompt function copied, we can override with our own.
    1.56 +    function fish_prompt
    1.57 +        # Prompt override?
    1.58 +        if test -n "__VIRTUAL_PROMPT__"
    1.59 +            printf "%s%s" "__VIRTUAL_PROMPT__" (set_color normal)
    1.60 +            _old_fish_prompt
    1.61 +            return
    1.62 +        end
    1.63 +        # ...Otherwise, prepend env
    1.64 +        set -l _checkbase (basename "$VIRTUAL_ENV")
    1.65 +        if test $_checkbase = "__"
    1.66 +            # special case for Aspen magic directories
    1.67 +            # see http://www.zetadev.com/software/aspen/
    1.68 +            printf "%s[%s]%s " (set_color -b blue white) (basename (dirname "$VIRTUAL_ENV")) (set_color normal) 
    1.69 +            _old_fish_prompt
    1.70 +        else
    1.71 +            printf "%s(%s)%s" (set_color -b blue white) (basename "$VIRTUAL_ENV") (set_color normal)
    1.72 +            _old_fish_prompt
    1.73 +        end
    1.74 +    end 
    1.75 +    
    1.76 +    set -gx _OLD_FISH_PROMPT_OVERRIDE "$VIRTUAL_ENV"
    1.77 +end

mercurial