diff options
| author | Jonathan Barronville <jonathanmarvens@users.noreply.github.com> | 2014-04-02 06:25:02 -0400 |
|---|---|---|
| committer | Matthew Iversen <teh.ivo@gmail.com> | 2015-09-19 22:07:07 +1000 |
| commit | 2da2d52c7d795b961ecae311b935fb3a5ed85643 (patch) | |
| tree | b3c71020b71a4f070d43e220d70ac687eb12a304 /virtualenv_embedded | |
| parent | 49d741812dc15feac4d5b3ff88eed8cf8c00eab5 (diff) | |
| download | virtualenv-2da2d52c7d795b961ecae311b935fb3a5ed85643.tar.gz | |
Cleaned up activate.fish.
Cleaned up activate.fish to be more *idiomatic* fish and removed a bit of unnecessary code (such as support for "Aspen magic directories" ... AFAIK and AFAICT, this is no longer the case).
- Jonathan
Diffstat (limited to 'virtualenv_embedded')
| -rw-r--r-- | virtualenv_embedded/activate.fish | 81 |
1 files changed, 36 insertions, 45 deletions
diff --git a/virtualenv_embedded/activate.fish b/virtualenv_embedded/activate.fish index eaa241d..97b9244 100644 --- a/virtualenv_embedded/activate.fish +++ b/virtualenv_embedded/activate.fish @@ -1,74 +1,65 @@ -# This file must be used with "source bin/activate.fish" *from fish* (http://fishshell.com) -# you cannot run it directly +# This file should be used using `. bin/activate.fish` *within a running fish ( http://fishshell.com ) session*. +# Do not run it directly. -function deactivate -d "Exit virtualenv and return to normal shell environment" - # reset old environment variables - if test -n "$_OLD_VIRTUAL_PATH" - set -gx PATH $_OLD_VIRTUAL_PATH - set -e _OLD_VIRTUAL_PATH +function deactivate -d 'Exit virtualenv mode and return to the normal environment.' + if test -n $_OLD_PATH + set -gx PATH $_OLD_PATH + set -e _OLD_PATH end - if test -n "$_OLD_VIRTUAL_PYTHONHOME" - set -gx PYTHONHOME $_OLD_VIRTUAL_PYTHONHOME - set -e _OLD_VIRTUAL_PYTHONHOME + + if test -n $_OLD_PYTHONHOME + set -gx PYTHONHOME $_OLD_PYTHONHOME + set -e _OLD_PYTHONHOME end - - if test -n "$_OLD_FISH_PROMPT_OVERRIDE" - # set an empty local fish_function_path, so fish_prompt doesn't automatically reload + + if test -n $_OLD_FISH_PROMPT_OVERRIDE + # Set an empty local `$fish_function_path` to allow the removal of `fish_prompt` using `functions -e`. set -l fish_function_path - # erase the virtualenv's fish_prompt function, and restore the original + + # Erase virtualenv's `fish_prompt` and restore the original. functions -e fish_prompt functions -c _old_fish_prompt fish_prompt functions -e _old_fish_prompt set -e _OLD_FISH_PROMPT_OVERRIDE end - + set -e VIRTUAL_ENV - if test "$argv[1]" != "nondestructive" - # Self destruct! + + if test $argv[1] != 'nondestructive' + # Self-destruct! functions -e deactivate end end -# unset irrelevant variables +# Unset irrelevant variables. deactivate nondestructive set -gx VIRTUAL_ENV "__VIRTUAL_ENV__" -set -gx _OLD_VIRTUAL_PATH $PATH -set -gx PATH "$VIRTUAL_ENV/__BIN_NAME__" $PATH +set -gx _OLD_PATH $PATH +set -gx PATH $VIRTUAL_ENV/"__BIN_NAME__" $PATH -# unset PYTHONHOME if set +# Unset `$PYTHONHOME` if set. if set -q PYTHONHOME - set -gx _OLD_VIRTUAL_PYTHONHOME $PYTHONHOME + set -gx _OLD_PYTHONHOME $PYTHONHOME set -e PYTHONHOME end -if test -z "$VIRTUAL_ENV_DISABLE_PROMPT" - # fish uses a function instead of an env var to generate the prompt. - - # copy the current fish_prompt function as the function _old_fish_prompt +if test \( -z $VIRTUALENV_DISABLE_PROMPT \) -o \( -z $VIRTUAL_ENV_DISABLE_PROMPT \) + # Copy the current `fish_prompt` function as `_old_fish_prompt`. functions -c fish_prompt _old_fish_prompt - - # with the original prompt function copied, we can override with our own. + function fish_prompt - # Prompt override? + # Prompt override provided? + # If not, just prepend the environment name. if test -n "__VIRTUAL_PROMPT__" - printf "%s%s" "__VIRTUAL_PROMPT__" (set_color normal) - _old_fish_prompt - return - end - # ...Otherwise, prepend env - set -l _checkbase (basename "$VIRTUAL_ENV") - if test $_checkbase = "__" - # special case for Aspen magic directories - # see http://www.zetadev.com/software/aspen/ - printf "%s[%s]%s " (set_color -b blue white) (basename (dirname "$VIRTUAL_ENV")) (set_color normal) - _old_fish_prompt + printf '%s%s' "__VIRTUAL_PROMPT__" (set_color normal) else - printf "%s(%s)%s" (set_color -b blue white) (basename "$VIRTUAL_ENV") (set_color normal) - _old_fish_prompt + printf '%svirtualenv:%s %s%s%s\n' (set_color white) (set_color normal) (set_color -b black white) (basename $VIRTUAL_ENV) (set_color normal) end - end - - set -gx _OLD_FISH_PROMPT_OVERRIDE "$VIRTUAL_ENV" + + _old_fish_prompt + end + + set -gx _OLD_FISH_PROMPT_OVERRIDE $VIRTUAL_ENV end |
