1
1
# This file must be dot sourced from PoSh; you cannot run it directly. Do this: . ./activate.ps1
2
2
3
3
$script :THIS_PATH = $myinvocation.mycommand.path
4
- $script :BASE_DIR = split-path ( resolve-path " $THIS_PATH /.." ) - Parent
4
+ $script :BASE_DIR = Split-Path ( Resolve-Path " $THIS_PATH /.." ) - Parent
5
5
6
- function global :deactivate ([switch ] $NonDestructive )
7
- {
8
- if (test-path variable:_OLD_VIRTUAL_PATH)
9
- {
6
+ function global :deactivate ([switch ] $NonDestructive ) {
7
+ if (Test-Path variable:_OLD_VIRTUAL_PATH) {
10
8
$env: PATH = $variable: _OLD_VIRTUAL_PATH
11
- remove-variable " _OLD_VIRTUAL_PATH" - scope global
9
+ Remove-Variable " _OLD_VIRTUAL_PATH" - Scope global
12
10
}
13
11
14
- if (test-path function:_old_virtual_prompt)
15
- {
12
+ if (Test-Path function:_old_virtual_prompt) {
16
13
$function: prompt = $function: _old_virtual_prompt
17
- remove-item function:\_old_virtual_prompt
14
+ Remove-Item function:\_old_virtual_prompt
18
15
}
19
16
20
- if ($env: VIRTUAL_ENV )
21
- {
22
- $old_env = split-path $env: VIRTUAL_ENV - leaf
23
- remove-item env:VIRTUAL_ENV - erroraction silentlycontinue
17
+ if ($env: VIRTUAL_ENV ) {
18
+ Remove-Item env:VIRTUAL_ENV - ErrorAction SilentlyContinue
24
19
}
25
20
26
- if (! $NonDestructive )
27
- {
21
+ if (! $NonDestructive ) {
28
22
# Self destruct!
29
- remove-item function:deactivate
30
- remove-item function:pydoc
23
+ Remove-Item function:deactivate
24
+ Remove-Item function:pydoc
31
25
}
32
26
}
33
27
34
- function global :pydoc
35
- {
28
+ function global :pydoc {
36
29
python - m pydoc $args
37
30
}
38
31
@@ -42,31 +35,28 @@ deactivate -nondestructive
42
35
$VIRTUAL_ENV = $BASE_DIR
43
36
$env: VIRTUAL_ENV = $VIRTUAL_ENV
44
37
45
- $global :_OLD_VIRTUAL_PATH = $env: PATH
38
+ New-Variable - Scope global - Name _OLD_VIRTUAL_PATH - Value $env: PATH
39
+
46
40
$env: PATH = " $env: VIRTUAL_ENV /__BIN_NAME____PATH_SEP__" + $env: PATH
47
- if (! $env: VIRTUAL_ENV_DISABLE_PROMPT )
48
- {
49
- function global :_old_virtual_prompt
50
- {
41
+ if (! $env: VIRTUAL_ENV_DISABLE_PROMPT ) {
42
+ function global :_old_virtual_prompt {
51
43
" "
52
44
}
53
45
$function: _old_virtual_prompt = $function: prompt
54
- if (" __VIRTUAL_PROMPT__" -ne " " )
55
- {
56
- function global :prompt
57
- {
46
+
47
+ if (" __VIRTUAL_PROMPT__" -ne " " ) {
48
+ function global :prompt {
58
49
# Add the custom prefix to the existing prompt
59
- write-host " __VIRTUAL_PROMPT__ " - nonewline
60
- & $ function: _old_virtual_prompt
50
+ $previous_prompt_value = & $ function: _old_virtual_prompt
51
+ ( " __VIRTUAL_PROMPT__ " + $previous_prompt_value )
61
52
}
62
53
}
63
- else
64
- {
65
- function global :prompt
66
- {
54
+ else {
55
+ function global :prompt {
67
56
# Add a prefix to the current prompt, but don't discard it.
68
- write-host " ($ ( split-path $env: VIRTUAL_ENV - leaf ) ) " - nonewline
69
- & $function: _old_virtual_prompt
57
+ $previous_prompt_value = & $function: _old_virtual_prompt
58
+ $new_prompt_value = " ($ ( Split-Path $env: VIRTUAL_ENV - Leaf ) ) "
59
+ ($new_prompt_value + $previous_prompt_value )
70
60
}
71
61
}
72
62
}
0 commit comments