You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

101 lines
3.0 KiB

4 years ago
  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 _bashify_path -d "Converts a fish path to something bash can recognize"
  4. set fishy_path $argv
  5. set bashy_path $fishy_path[1]
  6. for path_part in $fishy_path[2..-1]
  7. set bashy_path "$bashy_path:$path_part"
  8. end
  9. echo $bashy_path
  10. end
  11. function _fishify_path -d "Converts a bash path to something fish can recognize"
  12. echo $argv | tr ':' '\n'
  13. end
  14. function deactivate -d 'Exit virtualenv mode and return to the normal environment.'
  15. # reset old environment variables
  16. if test -n "$_OLD_VIRTUAL_PATH"
  17. # https://github.com/fish-shell/fish-shell/issues/436 altered PATH handling
  18. if test (echo $FISH_VERSION | tr "." "\n")[1] -lt 3
  19. set -gx PATH (_fishify_path $_OLD_VIRTUAL_PATH)
  20. else
  21. set -gx PATH $_OLD_VIRTUAL_PATH
  22. end
  23. set -e _OLD_VIRTUAL_PATH
  24. end
  25. if test -n "$_OLD_VIRTUAL_PYTHONHOME"
  26. set -gx PYTHONHOME $_OLD_VIRTUAL_PYTHONHOME
  27. set -e _OLD_VIRTUAL_PYTHONHOME
  28. end
  29. if test -n "$_OLD_FISH_PROMPT_OVERRIDE"
  30. # Set an empty local `$fish_function_path` to allow the removal of `fish_prompt` using `functions -e`.
  31. set -l fish_function_path
  32. # Erase virtualenv's `fish_prompt` and restore the original.
  33. functions -e fish_prompt
  34. functions -c _old_fish_prompt fish_prompt
  35. functions -e _old_fish_prompt
  36. set -e _OLD_FISH_PROMPT_OVERRIDE
  37. end
  38. set -e VIRTUAL_ENV
  39. if test "$argv[1]" != 'nondestructive'
  40. # Self-destruct!
  41. functions -e pydoc
  42. functions -e deactivate
  43. functions -e _bashify_path
  44. functions -e _fishify_path
  45. end
  46. end
  47. # Unset irrelevant variables.
  48. deactivate nondestructive
  49. set -gx VIRTUAL_ENV "/home/alpcentaur/ProjektA/PrototypeWebApp/venv"
  50. # https://github.com/fish-shell/fish-shell/issues/436 altered PATH handling
  51. if test (echo $FISH_VERSION | tr "." "\n")[1] -lt 3
  52. set -gx _OLD_VIRTUAL_PATH (_bashify_path $PATH)
  53. else
  54. set -gx _OLD_VIRTUAL_PATH $PATH
  55. end
  56. set -gx PATH "$VIRTUAL_ENV/bin" $PATH
  57. # Unset `$PYTHONHOME` if set.
  58. if set -q PYTHONHOME
  59. set -gx _OLD_VIRTUAL_PYTHONHOME $PYTHONHOME
  60. set -e PYTHONHOME
  61. end
  62. function pydoc
  63. python -m pydoc $argv
  64. end
  65. if test -z "$VIRTUAL_ENV_DISABLE_PROMPT"
  66. # Copy the current `fish_prompt` function as `_old_fish_prompt`.
  67. functions -c fish_prompt _old_fish_prompt
  68. function fish_prompt
  69. # Save the current $status, for fish_prompts that display it.
  70. set -l old_status $status
  71. # Prompt override provided?
  72. # If not, just prepend the environment name.
  73. if test -n ""
  74. printf '%s%s' "" (set_color normal)
  75. else
  76. printf '%s(%s) ' (set_color normal) (basename "$VIRTUAL_ENV")
  77. end
  78. # Restore the original $status
  79. echo "exit $old_status" | source
  80. _old_fish_prompt
  81. end
  82. set -gx _OLD_FISH_PROMPT_OVERRIDE "$VIRTUAL_ENV"
  83. end