@@ -11,8 +11,10 @@ export-env {
1111 ($x | describe ) == ' string'
1212 }
1313
14- def has-env [name : string ] {
15- $name in $env
14+ def has-env [... names ] {
15+ $names | each {|n |
16+ $n in $env
17+ } | all {|i | $i == true }
1618 }
1719
1820 # Emulates a `test -z`, but btter as it handles e.g 'false'
@@ -23,46 +25,26 @@ export-env {
2325 if ($parsed | describe ) == ' bool' {
2426 $parsed
2527 } else {
26- not ($env | get $name | is-empty )
28+ not ($env | get - i $name | is-empty )
2729 }
2830 } else {
2931 false
3032 }
3133 }
3234
33- let is_windows = ($nu .os-info.name | str downcase ) == ' windows'
3435 let virtual_env = ' __VIRTUAL_ENV__'
3536 let bin = ' __BIN_NAME__'
36- let path_sep = ( char esep )
37- let path_name = (if $is_windows {
38- if (has-env ' Path' ) {
37+
38+ let is_windows = ($nu .os-info.family ) == ' windows '
39+ let path_name = ( if (has-env ' Path' ) {
3940 ' Path'
4041 } else {
4142 ' PATH'
4243 }
43- } else {
44- ' PATH'
45- })
46-
47- let old_path = (
48- if $is_windows {
49- if (has-env ' Path' ) {
50- $env .Path
51- } else {
52- $env .PATH
53- }
54- } else {
55- $env .PATH
56- } | if (is-string $in ) {
57- # if Path/PATH is a string, make it a list
58- $in | split row $path_sep | path expand
59- } else {
60- $in
61- }
6244 )
6345
6446 let venv_path = ([$virtual_env $bin ] | path join )
65- let new_path = ($old_path | prepend $venv_path | str join $path_sep )
47+ let new_path = ($env | get $path_name | prepend $venv_path )
6648
6749 let new_env = {
6850 $path_name : $new_path
@@ -73,22 +55,18 @@ export-env {
7355 $new_env
7456 } else {
7557 # Creating the new prompt for the session
76- let virtual_prompt = (if (' __VIRTUAL_PROMPT__' == ' ' ) {
58+ let virtual_prompt = (if (' __VIRTUAL_PROMPT__' | is-empty ) {
7759 $' (char lparen )($virtual_env | path basename )(char rparen ) '
7860 } else {
7961 ' (__VIRTUAL_PROMPT__) '
8062 })
8163
8264 # Back up the old prompt builder
83- let old_prompt_command = (if (has-env ' VIRTUAL_ENV' ) and (has-env ' _OLD_PROMPT_COMMAND' ) {
84- $env ._OLD_PROMPT_COMMAND
85- } else {
86- if (has-env ' PROMPT_COMMAND' ) {
65+ let old_prompt_command = (if (has-env ' PROMPT_COMMAND' ) {
8766 $env .PROMPT_COMMAND
8867 } else {
8968 ' '
90- }
91- })
69+ })
9270
9371 # If there is no default prompt, then only the env is printed in the prompt
9472 let new_prompt = (if (has-env ' PROMPT_COMMAND' ) {
@@ -102,8 +80,6 @@ export-env {
10280 })
10381
10482 $new_env | merge {
105- _OLD_VIRTUAL_PATH : ($old_path | str join $path_sep )
106- _OLD_PROMPT_COMMAND : $old_prompt_command
10783 PROMPT_COMMAND : $new_prompt
10884 VIRTUAL_PROMPT : $virtual_prompt
10985 }
0 commit comments