activate.fish 2.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. # This file must be used with ". bin/activate.fish" *from fish* (http://fishshell.org)
  2. # you cannot run it directly
  3. function deactivate -d "Exit virtualenv and return to normal shell environment"
  4. # reset old environment variables
  5. if test -n "$_OLD_VIRTUAL_PATH"
  6. set -gx PATH $_OLD_VIRTUAL_PATH
  7. set -e _OLD_VIRTUAL_PATH
  8. end
  9. if test -n "$_OLD_VIRTUAL_PYTHONHOME"
  10. set -gx PYTHONHOME $_OLD_VIRTUAL_PYTHONHOME
  11. set -e _OLD_VIRTUAL_PYTHONHOME
  12. end
  13. if test -n "$_OLD_FISH_PROMPT_OVERRIDE"
  14. functions -e fish_prompt
  15. set -e _OLD_FISH_PROMPT_OVERRIDE
  16. end
  17. set -e VIRTUAL_ENV
  18. if test "$argv[1]" != "nondestructive"
  19. # Self destruct!
  20. functions -e deactivate
  21. end
  22. end
  23. # unset irrelavent variables
  24. deactivate nondestructive
  25. set -gx VIRTUAL_ENV "/home/daccorsi/sources/protos/pboard/tg2env"
  26. set -gx _OLD_VIRTUAL_PATH $PATH
  27. set -gx PATH "$VIRTUAL_ENV/bin" $PATH
  28. # unset PYTHONHOME if set
  29. if set -q PYTHONHOME
  30. set -gx _OLD_VIRTUAL_PYTHONHOME $PYTHONHOME
  31. set -e PYTHONHOME
  32. end
  33. if test -z "$VIRTUAL_ENV_DISABLE_PROMPT"
  34. # fish shell uses a function, instead of env vars,
  35. # to produce the prompt. Overriding the existing function is easy.
  36. # However, adding to the current prompt, instead of clobbering it,
  37. # is a little more work.
  38. set -l oldpromptfile (tempfile)
  39. if test $status
  40. # save the current fish_prompt function...
  41. echo "function _old_fish_prompt" >> $oldpromptfile
  42. echo -n \# >> $oldpromptfile
  43. functions fish_prompt >> $oldpromptfile
  44. # we've made the "_old_fish_prompt" file, source it.
  45. . $oldpromptfile
  46. rm -f $oldpromptfile
  47. if test -n ""
  48. # We've been given us a prompt override.
  49. #
  50. # FIXME: Unsure how to handle this *safely*. We could just eval()
  51. # whatever is given, but the risk is a bit much.
  52. echo "activate.fish: Alternative prompt prefix is not supported under fish-shell." 1>&2
  53. echo "activate.fish: Alter the fish_prompt in this file as needed." 1>&2
  54. end
  55. # with the original prompt function renamed, we can override with our own.
  56. function fish_prompt
  57. set -l _checkbase (basename "$VIRTUAL_ENV")
  58. if test $_checkbase = "__"
  59. # special case for Aspen magic directories
  60. # see http://www.zetadev.com/software/aspen/
  61. printf "%s[%s]%s %s" (set_color -b blue white) (basename (dirname "$VIRTUAL_ENV")) (set_color normal) (_old_fish_prompt)
  62. else
  63. printf "%s(%s)%s%s" (set_color -b blue white) (basename "$VIRTUAL_ENV") (set_color normal) (_old_fish_prompt)
  64. end
  65. end
  66. set -gx _OLD_FISH_PROMPT_OVERRIDE "$VIRTUAL_ENV"
  67. end
  68. end