Skip to content

Commit

Permalink
added a fish shell activate script
Browse files Browse the repository at this point in the history
  • Loading branch information
otherchirps committed Aug 29, 2010
1 parent 6337079 commit 51b5c7e
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 0 deletions.
26 changes: 26 additions & 0 deletions virtualenv.py
Expand Up @@ -873,6 +873,11 @@ def install_activate(home_dir, bin_dir, prompt=None):
files['activate'] = ACTIVATE_SH
else:
files = {'activate': ACTIVATE_SH}

# suppling activate.fish in addition to, not instead of, the
# bash script support.
files['activate.fish'] = ACTIVATE_FISH

files['activate_this.py'] = ACTIVATE_THIS
vname = os.path.basename(os.path.abspath(home_dir))
for name, content in files.items():
Expand Down Expand Up @@ -1443,6 +1448,27 @@ def after_install(options, home_dir):
LLK0j1y0Uwbmn438VZkVpqlfNKa/YET/53j+99G8H8tUhr9ZSXs2
""".decode("base64").decode("zlib")

##file activate.fish
ACTIVATE_FISH = """
eJytVt9v2kgQfuevmC5EFyowutdKrUQVTiAlECVcpFN7shZ7jFexd7ndtZ30r++sbYwNpvdSHhJ7
d358M/PNjIewjYWBSCQIaWYs7BAygyEUwsbAPNgJOeOBFTm36EXCxAw+Rlql4J4/wm1s7eHTbObe
TIxJ4im9Hw+G8K4yCLiUyoLOJAgLodAY2OR9MIgySRaVhBCPpgGmIbDFG8nlQtuMJyhz4DIEjTbT
EqwCqXTKEyjdAF0LrWSK0rIB0G9IkgYtqCRsX0LOteC7BE0pJSKwSGFOJbCRv7m/819WT9u/5/f+
43y7ZFAKuZ8zNd2/gTuGS8muHEK/AMrw/7z+s11u1svNw4Jdum7uzgE0F7+G0RVzYK6g+Wv1vPQf
nzYPj1t/87J4elrdtfAcy2WcB1do/0AEONhe532muu5r6SPKxfqlg4qNuN7n3/78l8GHz8CkkiEd
68wRBU+ghvCMSQTHuw/9aE8EazCUOIaQSYdDaI0Jz7s8abGy630wOJamBR6Y77defZ+dxC5YAaOS
Gx1ysVFLfeb7X1drfz1/WJClWryB22IEpYtOBtU/mP4HZ9Xuh9BiVJ88tq2UiWq48qOL079bPc+/
3i/qUh9b0LGjblCaIgZ4U44JCGks8hBU5PrT5dtMajVqbqJUmAUINkao6OXBJketRSjkvjzGN2Gs
e2nmB00u5Obdq80sVYGkMgEeVkqq1AsyqjJVuDLrlDgkwlo38pRGKJR+rU3Uhtab7eITPFvh4pAm
I6FYFTXMXIQIJjsclLYQKU32jaWBWJk3ExpgvLYDpf8m+2WqIOX6FbUHqz0NtDIcsuHkUuUGlncq
R+KGWWW2HNC3FtODexp3OmZkLLeZabWGIUp3Qm91bZM9z/MaFQxiBazJq09+/ZYOgy9fYNQB01Wl
UfJ9+AuhU1O2kVyXH0KBf1AMKQ+rQNglJKcwAaMyTbQR9hSMd82qTmEaXbts+3a7z3ml+uyFpJ1z
ljpaNZKnGE4IpttyoCqmYqVKkEAV0rsIv3d6tsrtBzEGrztuqNbur3PS7Ts27ug1FGhpfnYTiXXE
alYcMBAUTOCkHOnmdCIpx3sR1NuZAkbTp4rUAdWmL4rC+4GWCpN7gUpnRkW24Bpn3FmbXSgfiOM2
AnZjbm/M+MbAjWFwSwH7gUoIxHQHuySjzMXC4rgVNyHqi7+tW30R0NE5O7pZwsTg78P1G/DUnwX1
8+VHx9VNeua8u9R+Arnp9QQ=
""".decode("base64").decode("zlib")

##file activate.bat
ACTIVATE_BAT = """
eJyFUkEKgzAQvAfyhz0YaL9QEWpRqlSjWGspFPZQTevFHOr/adQaU1GaUzI7Mzu7ZF89XhKkEJS8
Expand Down
72 changes: 72 additions & 0 deletions virtualenv_support/activate.fish
@@ -0,0 +1,72 @@
# This file must be used with ". bin/activate.fish" *from fish* (http://fishshell.org)
# you cannot 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
end
if test -n "$_OLD_VIRTUAL_PYTHONHOME"
set -gx PYTHONHOME $_OLD_VIRTUAL_PYTHONHOME
set -e _OLD_VIRTUAL_PYTHONHOME
end

if test -n "$_OLD_FISH_PROMPT_OVERRIDE"
functions -e fish_prompt
set -e _OLD_FISH_PROMPT_OVERRIDE
end

set -e VIRTUAL_ENV
if test "$argv[1]" != "nondestructive"
# Self destruct!
functions -e deactivate
end
end

# unset irrelavent variables
deactivate nondestructive

set -gx VIRTUAL_ENV "__VIRTUAL_ENV__"

set -gx _OLD_VIRTUAL_PATH $PATH
set -gx PATH "$VIRTUAL_ENV/__BIN_NAME__" $PATH

# unset PYTHONHOME if set
if set -q PYTHONHOME
set -gx _OLD_VIRTUAL_PYTHONHOME $PYTHONHOME
set -e PYTHONHOME
end

if test -z "$VIRTUAL_ENV_DISABLE_PROMPT"
# fish shell uses a function, instead of env vars,
# to produce the prompt. Overriding the existing function is easy.
# However, adding to the current prompt is a little more work.
#
# NOTE: Still unsure how to provide support for custom prompts, via
# the VIRTUAL_PROMPT marker. Ignoring for the moment.
set -l oldpromptfile (tempfile)
if test $status
# save the current fish_prompt function...
echo "function _old_fish_prompt" >> $oldpromptfile
echo -n \# >> $oldpromptfile
functions fish_prompt >> $oldpromptfile
# we've made the "_old_fish_prompt" file, source it.
. $oldpromptfile
rm -f $oldpromptfile

# with the original prompt function renamed, we can override with our own.
function fish_prompt
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 %s" (set_color -b blue white) (basename dirname "$VIRTUAL_ENV") (set_color normal) (_old_fish_prompt)
else
printf "%s(%s)%s %s" (set_color -b blue white) (basename "$VIRTUAL_ENV") (set_color normal) (_old_fish_prompt)
end
end
set -gx _OLD_FISH_PROMPT_OVERRIDE "$VIRTUAL_ENV"
end
end

0 comments on commit 51b5c7e

Please sign in to comment.