Created
July 9, 2024 16:17
-
-
Save ShenTengTu/240efbf515ac38b31dd726830d595d03 to your computer and use it in GitHub Desktop.
Custom prompt of PowerShell (posh-git, Python virtualenv)
This file contains 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
### Custom prompt ### | |
Import-Module posh-git | |
# disable default python virtualenv prompt | |
$env:VIRTUAL_ENV_DISABLE_PROMPT = "1" | |
# store the original prompt function | |
function _prompt { | |
"" | |
} | |
$function:_prompt = $function:prompt | |
# get python virtualenv name | |
function _py_virtual_env { | |
$venv = "" | |
if ($env:VIRTUAL_ENV) { | |
$venv = "$( Split-Path $env:VIRTUAL_ENV -Leaf )" | |
} | |
$venv | |
} | |
# make custom prompt prefix | |
function _prompt_prefix { | |
$prefix = "┌▫" | |
$venv = $(_py_virtual_env) | |
if ($venv) { | |
$prefix += " ($venv)" | |
} | |
$info = '$(Get-PromptConnectionInfo -Format "[{1}@{0}]: ")' | |
("$prefix $info") | |
} | |
# make custom prompt suffix | |
function _prompt_suffix { | |
"`n└$(">" * ($nestedPromptLevel + 1)) " | |
} | |
# set the custom prompt | |
function prompt { | |
$GitPromptSettings.DefaultPromptPrefix.Text = $(_prompt_prefix) | |
$GitPromptSettings.DefaultPromptSuffix.Text = $(_prompt_suffix) | |
Invoke-Command (Get-Item function:_prompt).ScriptBlock | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment