Skip to content

Commit 2da2d52

Browse files
jonathanmarvensIvoz
authored andcommitted
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
1 parent 49d7418 commit 2da2d52

File tree

1 file changed

+36
-45
lines changed

1 file changed

+36
-45
lines changed

virtualenv_embedded/activate.fish

Lines changed: 36 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,65 @@
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.
33

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
98
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
1313
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`.
1717
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.
1920
functions -e fish_prompt
2021
functions -c _old_fish_prompt fish_prompt
2122
functions -e _old_fish_prompt
2223
set -e _OLD_FISH_PROMPT_OVERRIDE
2324
end
24-
25+
2526
set -e VIRTUAL_ENV
26-
if test "$argv[1]" != "nondestructive"
27-
# Self destruct!
27+
28+
if test $argv[1] != 'nondestructive'
29+
# Self-destruct!
2830
functions -e deactivate
2931
end
3032
end
3133

32-
# unset irrelevant variables
34+
# Unset irrelevant variables.
3335
deactivate nondestructive
3436

3537
set -gx VIRTUAL_ENV "__VIRTUAL_ENV__"
3638

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
3941

40-
# unset PYTHONHOME if set
42+
# Unset `$PYTHONHOME` if set.
4143
if set -q PYTHONHOME
42-
set -gx _OLD_VIRTUAL_PYTHONHOME $PYTHONHOME
44+
set -gx _OLD_PYTHONHOME $PYTHONHOME
4345
set -e PYTHONHOME
4446
end
4547

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`.
5050
functions -c fish_prompt _old_fish_prompt
51-
52-
# with the original prompt function copied, we can override with our own.
51+
5352
function fish_prompt
54-
# Prompt override?
53+
# Prompt override provided?
54+
# If not, just prepend the environment name.
5555
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)
6757
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)
7059
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
7465
end

0 commit comments

Comments
 (0)