activate.nu 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. # Setting all environment variables for the venv
  2. let path-name = (if ((sys).host.name == "Windows") { "Path" } { "PATH" })
  3. let virtual-env = "D:\TestPythonProject\TEST\venv"
  4. let bin = "Scripts"
  5. let path-sep = ";"
  6. let old-path = ($nu.path | str collect ($path-sep))
  7. let venv-path = ([$virtual-env $bin] | path join)
  8. let new-path = ($nu.path | prepend $venv-path | str collect ($path-sep))
  9. # environment variables that will be batched loaded to the virtual env
  10. let new-env = ([
  11. [name, value];
  12. [$path-name $new-path]
  13. [_OLD_VIRTUAL_PATH $old-path]
  14. [VIRTUAL_ENV $virtual-env]
  15. ])
  16. load-env $new-env
  17. # Creating the new prompt for the session
  18. let virtual_prompt = (if ("" != "") {
  19. "() "
  20. } {
  21. (build-string '(' ($virtual-env | path basename) ') ')
  22. }
  23. )
  24. # If there is no default prompt, then only the env is printed in the prompt
  25. let new_prompt = (if ( config | select prompt | empty? ) {
  26. ($"build-string '($virtual_prompt)'")
  27. } {
  28. ($"build-string '($virtual_prompt)' (config get prompt | str find-replace "build-string" "")")
  29. })
  30. let-env PROMPT_COMMAND = $new_prompt
  31. # We are using alias as the function definitions because only aliases can be
  32. # removed from the scope
  33. alias pydoc = python -m pydoc
  34. alias deactivate = source "D:\TestPythonProject\TEST\venv\Scripts\deactivate.nu"