Project

General

Profile

Statistics
| Branch: | Revision:

root / env / bin / activate.fish @ 1a305335

History | View | Annotate | Download (2.8 KB)

1
# This file must be used with ". bin/activate.fish" *from fish* (http://fishshell.org)
2
# you cannot run it directly
3

    
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
14

    
15
    if test -n "$_OLD_FISH_PROMPT_OVERRIDE"
16
        functions -e fish_prompt
17
        set -e _OLD_FISH_PROMPT_OVERRIDE
18
    end
19

    
20
    set -e VIRTUAL_ENV
21
    if test "$argv[1]" != "nondestructive"
22
        # Self destruct!
23
        functions -e deactivate
24
    end
25
end
26

    
27
# unset irrelavent variables
28
deactivate nondestructive
29

    
30
set -gx VIRTUAL_ENV "/home/officers/tooltron/env"
31

    
32
set -gx _OLD_VIRTUAL_PATH $PATH
33
set -gx PATH "$VIRTUAL_ENV/bin" $PATH
34

    
35
# unset PYTHONHOME if set
36
if set -q PYTHONHOME
37
    set -gx _OLD_VIRTUAL_PYTHONHOME $PYTHONHOME
38
    set -e PYTHONHOME
39
end
40

    
41
if test -z "$VIRTUAL_ENV_DISABLE_PROMPT"
42
    # fish shell uses a function, instead of env vars,
43
    # to produce the prompt. Overriding the existing function is easy.
44
    # However, adding to the current prompt, instead of clobbering it,
45
    # is a little more work.
46
    set -l oldpromptfile (tempfile)
47
    if test $status
48
        # save the current fish_prompt function...
49
        echo "function _old_fish_prompt" >> $oldpromptfile
50
        echo -n \# >> $oldpromptfile
51
        functions fish_prompt >> $oldpromptfile
52
        # we've made the "_old_fish_prompt" file, source it.
53
        . $oldpromptfile
54
        rm -f $oldpromptfile
55
        
56
        if test -n ""
57
            # We've been given us a prompt override.
58
            # 
59
            # FIXME: Unsure how to handle this *safely*. We could just eval()
60
            #   whatever is given, but the risk is a bit much.
61
            echo "activate.fish: Alternative prompt prefix is not supported under fish-shell." 1>&2
62
            echo "activate.fish: Alter the fish_prompt in this file as needed." 1>&2
63
        end        
64
        
65
        # with the original prompt function renamed, we can override with our own.
66
        function fish_prompt                
67
            set -l _checkbase (basename "$VIRTUAL_ENV")
68
            if test $_checkbase = "__"
69
                # special case for Aspen magic directories
70
                # see http://www.zetadev.com/software/aspen/
71
                printf "%s[%s]%s %s" (set_color -b blue white) (basename (dirname "$VIRTUAL_ENV")) (set_color normal) (_old_fish_prompt)
72
            else
73
                printf "%s(%s)%s%s" (set_color -b blue white) (basename "$VIRTUAL_ENV") (set_color normal) (_old_fish_prompt)
74
            end
75
        end 
76
        set -gx _OLD_FISH_PROMPT_OVERRIDE "$VIRTUAL_ENV"
77
    end
78
end
79