summaryrefslogtreecommitdiff
path: root/src/virtualenv/activation/nushell/activate.nu
diff options
context:
space:
mode:
authorFernando Herrera <fernando.j.herrera@gmail.com>2021-09-16 13:10:42 +0100
committerGitHub <noreply@github.com>2021-09-16 13:10:42 +0100
commite0410cafc8feedf72562174dee983fc709a5a36e (patch)
treed3043a56eeec1982b0157b9f7a9fe84085814ee5 /src/virtualenv/activation/nushell/activate.nu
parent1cc503bfadc2c0e8c3ecac6c0a3f430ee601d9a0 (diff)
downloadvirtualenv-e0410cafc8feedf72562174dee983fc709a5a36e.tar.gz
Nushell activation scripts (#2170)
Diffstat (limited to 'src/virtualenv/activation/nushell/activate.nu')
-rw-r--r--src/virtualenv/activation/nushell/activate.nu40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/virtualenv/activation/nushell/activate.nu b/src/virtualenv/activation/nushell/activate.nu
new file mode 100644
index 0000000..f0a4da4
--- /dev/null
+++ b/src/virtualenv/activation/nushell/activate.nu
@@ -0,0 +1,40 @@
+# Setting all environment variables for the venv
+let virtual-env = "__VIRTUAL_ENV__"
+let bin = "__BIN_NAME__"
+let path-sep = "__PATH_SEP__"
+
+let old-path = ($nu.path | str collect ($path-sep))
+
+let venv-path = ([$virtual-env $bin] | path join)
+let new-path = ($nu.path | prepend $venv-path | str collect ($path-sep))
+
+# environment variables that will be batched loaded to the virtual env
+let new-env = ([
+ [name, value];
+ [PATH $new-path]
+ [_OLD_VIRTUAL_PATH $old-path]
+ [VIRTUAL_ENV $virtual-env]
+])
+
+load-env $new-env
+
+# Creating the new prompt for the session
+let virtual_prompt = (if ("__VIRTUAL_PROMPT__" != "") {
+ "__VIRTUAL_PROMPT__"
+} {
+ $virtual-env | path basename
+}
+)
+
+# If there is no default prompt, then only the env is printed in the prompt
+let new_prompt = (if ( config | select prompt | empty? ) {
+ ($"build-string '(char lparen)' '($virtual_prompt)' '(char rparen) ' ")
+} {
+ ($"build-string '(char lparen)' '($virtual_prompt)' '(char rparen) ' (config get prompt | str find-replace "build-string" "")")
+})
+let-env PROMPT_COMMAND = $new_prompt
+
+# We are using alias as the function definitions because only aliases can be
+# removed from the scope
+alias pydoc = python -m pydoc
+alias deactivate = source "__DEACTIVATE_PATH__"