Created
April 1, 2020 15:51
-
-
Save HymanZHAN/44ddfc87ad45920cbd4314323ecdd404 to your computer and use it in GitHub Desktop.
Custom (actually just commented line 56) Activate.ps1 of virtualenv to use with starship.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$script:THIS_PATH = $myinvocation.mycommand.path | |
$script:BASE_DIR = Split-Path (Resolve-Path "$THIS_PATH/..") -Parent | |
function global:deactivate([switch] $NonDestructive) { | |
if (Test-Path variable:_OLD_VIRTUAL_PATH) { | |
$env:PATH = $variable:_OLD_VIRTUAL_PATH | |
Remove-Variable "_OLD_VIRTUAL_PATH" -Scope global | |
} | |
if (Test-Path function:_old_virtual_prompt) { | |
$function:prompt = $function:_old_virtual_prompt | |
Remove-Item function:\_old_virtual_prompt | |
} | |
if ($env:VIRTUAL_ENV) { | |
Remove-Item env:VIRTUAL_ENV -ErrorAction SilentlyContinue | |
} | |
if (!$NonDestructive) { | |
# Self destruct! | |
Remove-Item function:deactivate | |
Remove-Item function:pydoc | |
} | |
} | |
function global:pydoc { | |
python -m pydoc $args | |
} | |
# unset irrelevant variables | |
deactivate -nondestructive | |
$VIRTUAL_ENV = $BASE_DIR | |
$env:VIRTUAL_ENV = $VIRTUAL_ENV | |
New-Variable -Scope global -Name _OLD_VIRTUAL_PATH -Value $env:PATH | |
$env:PATH = "$env:VIRTUAL_ENV/Scripts;" + $env:PATH | |
if (!$env:VIRTUAL_ENV_DISABLE_PROMPT) { | |
function global:_old_virtual_prompt { | |
"" | |
} | |
$function:_old_virtual_prompt = $function:prompt | |
if ("" -ne "") { | |
function global:prompt { | |
# Add the custom prefix to the existing prompt | |
$previous_prompt_value = & $function:_old_virtual_prompt | |
("" + $previous_prompt_value) | |
} | |
} | |
else { | |
function global:prompt { | |
# Add a prefix to the current prompt, but don't discard it. | |
$previous_prompt_value = & $function:_old_virtual_prompt | |
# $new_prompt_value = "($( Split-Path $env:VIRTUAL_ENV -Leaf )) " | |
$previous_prompt_value | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment