activate.fish 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. # This file must be used using `source bin/activate.fish` *within a running fish ( http://fishshell.com ) session*.
  2. # Do not run it directly.
  3. function deactivate -d 'Exit virtualenv mode and return to the normal 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 __TCL_LIBRARY__
  10. if test -n "$_OLD_VIRTUAL_TCL_LIBRARY";
  11. set -gx TCL_LIBRARY "$_OLD_VIRTUAL_TCL_LIBRARY";
  12. set -e _OLD_VIRTUAL_TCL_LIBRARY;
  13. else;
  14. set -e TCL_LIBRARY;
  15. end
  16. end
  17. if test -n __TK_LIBRARY__
  18. if test -n "$_OLD_VIRTUAL_TK_LIBRARY";
  19. set -gx TK_LIBRARY "$_OLD_VIRTUAL_TK_LIBRARY";
  20. set -e _OLD_VIRTUAL_TK_LIBRARY;
  21. else;
  22. set -e TK_LIBRARY;
  23. end
  24. end
  25. if test -n "$_OLD_PKG_CONFIG_PATH"
  26. set -gx PKG_CONFIG_PATH "$_OLD_PKG_CONFIG_PATH"
  27. set -e _OLD_PKG_CONFIG_PATH
  28. end
  29. if test -n "$_OLD_VIRTUAL_PYTHONHOME"
  30. set -gx PYTHONHOME "$_OLD_VIRTUAL_PYTHONHOME"
  31. set -e _OLD_VIRTUAL_PYTHONHOME
  32. end
  33. if test -n "$_OLD_FISH_PROMPT_OVERRIDE"
  34. and functions -q _old_fish_prompt
  35. # Set an empty local `$fish_function_path` to allow the removal of `fish_prompt` using `functions -e`.
  36. set -l fish_function_path
  37. # Erase virtualenv's `fish_prompt` and restore the original.
  38. functions -e fish_prompt
  39. functions -c _old_fish_prompt fish_prompt
  40. functions -e _old_fish_prompt
  41. set -e _OLD_FISH_PROMPT_OVERRIDE
  42. end
  43. set -e VIRTUAL_ENV
  44. set -e VIRTUAL_ENV_PROMPT
  45. if test "$argv[1]" != 'nondestructive'
  46. # Self-destruct!
  47. functions -e pydoc
  48. functions -e deactivate
  49. end
  50. end
  51. # Unset irrelevant variables.
  52. deactivate nondestructive
  53. set -gx VIRTUAL_ENV __VIRTUAL_ENV__
  54. set -gx _OLD_PKG_CONFIG_PATH "$PKG_CONFIG_PATH"
  55. set -gx PKG_CONFIG_PATH "$VIRTUAL_ENV/lib/pkgconfig:$PKG_CONFIG_PATH"
  56. set -gx _OLD_VIRTUAL_PATH $PATH
  57. set -gx PATH "$VIRTUAL_ENV"'/'__BIN_NAME__ $PATH
  58. if test -n __TCL_LIBRARY__
  59. if set -q TCL_LIBRARY;
  60. set -gx _OLD_VIRTUAL_TCL_LIBRARY $TCL_LIBRARY;
  61. end
  62. set -gx TCL_LIBRARY '__TCL_LIBRARY__'
  63. end
  64. if test -n __TK_LIBRARY__
  65. if set -q TK_LIBRARY;
  66. set -gx _OLD_VIRTUAL_TK_LIBRARY $TK_LIBRARY;
  67. end
  68. set -gx TK_LIBRARY '__TK_LIBRARY__'
  69. end
  70. # Prompt override provided?
  71. # If not, just use the environment name.
  72. if test -n __VIRTUAL_PROMPT__
  73. set -gx VIRTUAL_ENV_PROMPT __VIRTUAL_PROMPT__
  74. else
  75. set -gx VIRTUAL_ENV_PROMPT (basename "$VIRTUAL_ENV")
  76. end
  77. # Unset `$PYTHONHOME` if set.
  78. if set -q PYTHONHOME
  79. set -gx _OLD_VIRTUAL_PYTHONHOME $PYTHONHOME
  80. set -e PYTHONHOME
  81. end
  82. function pydoc
  83. python -m pydoc $argv
  84. end
  85. if test -z "$VIRTUAL_ENV_DISABLE_PROMPT"
  86. # Copy the current `fish_prompt` function as `_old_fish_prompt`.
  87. functions -c fish_prompt _old_fish_prompt
  88. function fish_prompt
  89. set -l old_status $status
  90. # Run the user's prompt first; it might depend on (pipe)status.
  91. set -l prompt (_old_fish_prompt)
  92. printf '(%s) ' $VIRTUAL_ENV_PROMPT
  93. string join -- \n $prompt # handle multi-line prompts
  94. echo "exit $old_status" | .
  95. end
  96. set -gx _OLD_FISH_PROMPT_OVERRIDE "$VIRTUAL_ENV"
  97. end