Andrew Svetlov | 65e9c57 | 2012-10-04 21:48:58 +0300 | [diff] [blame] | 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 | . ( begin |
| 19 | printf "function fish_prompt\n\t#" |
| 20 | functions _old_fish_prompt |
| 21 | end | psub ) |
| 22 | functions -e _old_fish_prompt |
| 23 | end |
| 24 | |
| 25 | set -e VIRTUAL_ENV |
| 26 | if test "$argv[1]" != "nondestructive" |
| 27 | # Self destruct! |
| 28 | functions -e deactivate |
| 29 | end |
| 30 | end |
| 31 | |
| 32 | # unset irrelavent variables |
| 33 | deactivate nondestructive |
| 34 | |
| 35 | set -gx VIRTUAL_ENV "__VENV_DIR__" |
| 36 | |
| 37 | set -gx _OLD_VIRTUAL_PATH $PATH |
| 38 | set -gx PATH "$VIRTUAL_ENV/__VENV_BIN_NAME__" $PATH |
| 39 | |
| 40 | # unset PYTHONHOME if set |
| 41 | if set -q PYTHONHOME |
| 42 | set -gx _OLD_VIRTUAL_PYTHONHOME $PYTHONHOME |
| 43 | set -e PYTHONHOME |
| 44 | end |
| 45 | |
| 46 | if test -z "$VIRTUAL_ENV_DISABLE_PROMPT" |
| 47 | # fish uses a function instead of an env var to generate the prompt. |
| 48 | |
| 49 | # save the current fish_prompt function as the function _old_fish_prompt |
| 50 | . ( begin |
| 51 | printf "function _old_fish_prompt\n\t#" |
| 52 | functions fish_prompt |
| 53 | end | psub ) |
| 54 | |
| 55 | # with the original prompt function renamed, we can override with our own. |
| 56 | function fish_prompt |
| 57 | # Prompt override? |
| 58 | if test -n "__VENV_NAME__" |
| 59 | printf "%s%s%s" "__VENV_NAME__" (set_color normal) (_old_fish_prompt) |
| 60 | return |
| 61 | end |
| 62 | # ...Otherwise, prepend env |
| 63 | set -l _checkbase (basename "$VIRTUAL_ENV") |
| 64 | if test $_checkbase = "__" |
| 65 | # special case for Aspen magic directories |
| 66 | # see http://www.zetadev.com/software/aspen/ |
| 67 | printf "%s[%s]%s %s" (set_color -b blue white) (basename (dirname "$VIRTUAL_ENV")) (set_color normal) (_old_fish_prompt) |
| 68 | else |
| 69 | printf "%s(%s)%s%s" (set_color -b blue white) (basename "$VIRTUAL_ENV") (set_color normal) (_old_fish_prompt) |
| 70 | end |
| 71 | end |
| 72 | |
| 73 | set -gx _OLD_FISH_PROMPT_OVERRIDE "$VIRTUAL_ENV" |
| 74 | end |