|
1 |
| -# This file must be used with "source bin/activate.fish" *from fish* (http://fishshell.com) |
2 |
| -# you cannot run it directly |
| 1 | +# This file should be used using `. bin/activate.fish` *within a running fish ( http://fishshell.com ) session*. |
| 2 | +# Do not run it directly. |
3 | 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 |
| 4 | +function deactivate -d 'Exit virtualenv mode and return to the normal environment.' |
| 5 | + if test -n $_OLD_PATH |
| 6 | + set -gx PATH $_OLD_PATH |
| 7 | + set -e _OLD_PATH |
9 | 8 | end
|
10 |
| - if test -n "$_OLD_VIRTUAL_PYTHONHOME" |
11 |
| - set -gx PYTHONHOME $_OLD_VIRTUAL_PYTHONHOME |
12 |
| - set -e _OLD_VIRTUAL_PYTHONHOME |
| 9 | + |
| 10 | + if test -n $_OLD_PYTHONHOME |
| 11 | + set -gx PYTHONHOME $_OLD_PYTHONHOME |
| 12 | + set -e _OLD_PYTHONHOME |
13 | 13 | end
|
14 |
| - |
15 |
| - if test -n "$_OLD_FISH_PROMPT_OVERRIDE" |
16 |
| - # set an empty local fish_function_path, so fish_prompt doesn't automatically reload |
| 14 | + |
| 15 | + if test -n $_OLD_FISH_PROMPT_OVERRIDE |
| 16 | + # Set an empty local `$fish_function_path` to allow the removal of `fish_prompt` using `functions -e`. |
17 | 17 | set -l fish_function_path
|
18 |
| - # erase the virtualenv's fish_prompt function, and restore the original |
| 18 | + |
| 19 | + # Erase virtualenv's `fish_prompt` and restore the original. |
19 | 20 | functions -e fish_prompt
|
20 | 21 | functions -c _old_fish_prompt fish_prompt
|
21 | 22 | functions -e _old_fish_prompt
|
22 | 23 | set -e _OLD_FISH_PROMPT_OVERRIDE
|
23 | 24 | end
|
24 |
| - |
| 25 | + |
25 | 26 | set -e VIRTUAL_ENV
|
26 |
| - if test "$argv[1]" != "nondestructive" |
27 |
| - # Self destruct! |
| 27 | + |
| 28 | + if test $argv[1] != 'nondestructive' |
| 29 | + # Self-destruct! |
28 | 30 | functions -e deactivate
|
29 | 31 | end
|
30 | 32 | end
|
31 | 33 |
|
32 |
| -# unset irrelevant variables |
| 34 | +# Unset irrelevant variables. |
33 | 35 | deactivate nondestructive
|
34 | 36 |
|
35 | 37 | set -gx VIRTUAL_ENV "__VIRTUAL_ENV__"
|
36 | 38 |
|
37 |
| -set -gx _OLD_VIRTUAL_PATH $PATH |
38 |
| -set -gx PATH "$VIRTUAL_ENV/__BIN_NAME__" $PATH |
| 39 | +set -gx _OLD_PATH $PATH |
| 40 | +set -gx PATH $VIRTUAL_ENV/"__BIN_NAME__" $PATH |
39 | 41 |
|
40 |
| -# unset PYTHONHOME if set |
| 42 | +# Unset `$PYTHONHOME` if set. |
41 | 43 | if set -q PYTHONHOME
|
42 |
| - set -gx _OLD_VIRTUAL_PYTHONHOME $PYTHONHOME |
| 44 | + set -gx _OLD_PYTHONHOME $PYTHONHOME |
43 | 45 | set -e PYTHONHOME
|
44 | 46 | end
|
45 | 47 |
|
46 |
| -if test -z "$VIRTUAL_ENV_DISABLE_PROMPT" |
47 |
| - # fish uses a function instead of an env var to generate the prompt. |
48 |
| - |
49 |
| - # copy the current fish_prompt function as the function _old_fish_prompt |
| 48 | +if test \( -z $VIRTUALENV_DISABLE_PROMPT \) -o \( -z $VIRTUAL_ENV_DISABLE_PROMPT \) |
| 49 | + # Copy the current `fish_prompt` function as `_old_fish_prompt`. |
50 | 50 | functions -c fish_prompt _old_fish_prompt
|
51 |
| - |
52 |
| - # with the original prompt function copied, we can override with our own. |
| 51 | + |
53 | 52 | function fish_prompt
|
54 |
| - # Prompt override? |
| 53 | + # Prompt override provided? |
| 54 | + # If not, just prepend the environment name. |
55 | 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 |
| 56 | + printf '%s%s' "__VIRTUAL_PROMPT__" (set_color normal) |
67 | 57 | else
|
68 |
| - printf "%s(%s)%s" (set_color -b blue white) (basename "$VIRTUAL_ENV") (set_color normal) |
69 |
| - _old_fish_prompt |
| 58 | + printf '%svirtualenv:%s %s%s%s\n' (set_color white) (set_color normal) (set_color -b black white) (basename $VIRTUAL_ENV) (set_color normal) |
70 | 59 | end
|
71 |
| - end |
72 |
| - |
73 |
| - set -gx _OLD_FISH_PROMPT_OVERRIDE "$VIRTUAL_ENV" |
| 60 | + |
| 61 | + _old_fish_prompt |
| 62 | + end |
| 63 | + |
| 64 | + set -gx _OLD_FISH_PROMPT_OVERRIDE $VIRTUAL_ENV |
74 | 65 | end
|
0 commit comments