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.

60 lines
1.5 KiB

4 years ago
  1. # This file must be dot sourced from PoSh; you cannot run it directly. Do this: . ./activate.ps1
  2. $script:THIS_PATH = $myinvocation.mycommand.path
  3. $script:BASE_DIR = split-path (resolve-path "$THIS_PATH/..") -Parent
  4. function global:deactivate([switch] $NonDestructive)
  5. {
  6. if (test-path variable:_OLD_VIRTUAL_PATH)
  7. {
  8. $env:PATH = $variable:_OLD_VIRTUAL_PATH
  9. remove-variable "_OLD_VIRTUAL_PATH" -scope global
  10. }
  11. if (test-path function:_old_virtual_prompt)
  12. {
  13. $function:prompt = $function:_old_virtual_prompt
  14. remove-item function:\_old_virtual_prompt
  15. }
  16. if ($env:VIRTUAL_ENV)
  17. {
  18. $old_env = split-path $env:VIRTUAL_ENV -leaf
  19. remove-item env:VIRTUAL_ENV -erroraction silentlycontinue
  20. }
  21. if (!$NonDestructive)
  22. {
  23. # Self destruct!
  24. remove-item function:deactivate
  25. remove-item function:pydoc
  26. }
  27. }
  28. function global:pydoc
  29. {
  30. python -m pydoc $args
  31. }
  32. # unset irrelevant variables
  33. deactivate -nondestructive
  34. $VIRTUAL_ENV = $BASE_DIR
  35. $env:VIRTUAL_ENV = $VIRTUAL_ENV
  36. $global:_OLD_VIRTUAL_PATH = $env:PATH
  37. $env:PATH = "$env:VIRTUAL_ENV/bin:" + $env:PATH
  38. if (!$env:VIRTUAL_ENV_DISABLE_PROMPT)
  39. {
  40. function global:_old_virtual_prompt
  41. {
  42. ""
  43. }
  44. $function:_old_virtual_prompt = $function:prompt
  45. function global:prompt
  46. {
  47. # Add a prefix to the current prompt, but don't discard it.
  48. write-host "($( split-path $env:VIRTUAL_ENV -leaf )) " -nonewline
  49. & $function:_old_virtual_prompt
  50. }
  51. }