powershell 从CMD中删除虚拟环境名称

2cmtqfgy  于 2022-12-04  发布在  Shell
关注(0)|答案(1)|浏览(108)

每次你激活一个虚拟环境时,它会在cmd或powershell上显示名称。我想删除它或只是不显示它。有什么办法吗?
示例:example
我搜索了超过2天的每一种语言,我没有找到。

col17t5w

col17t5w1#

你必须定义一个新的prompt函数来覆盖你当前的函数。

function prompt {
  $identity = [Security.Principal.WindowsIdentity]::GetCurrent()
  $principal = [Security.Principal.WindowsPrincipal] $identity
  $adminRole = [Security.Principal.WindowsBuiltInRole]::Administrator

  $(if (Test-Path variable:/PSDebugContext) { '[DBG]: ' }
    elseif($principal.IsInRole($adminRole)) { "[ADMIN]: " }
    else { '' }
  ) + 'PS ' + $(Get-Location) +
    $(if ($NestedPromptLevel -ge 1) { '>>' }) + '> '
}

如果您以管理员身份运行ps,它将给出类似[ADMIN]: PS C:\ps-test>提示,否则将给出PS C:\ps-test>提示。
如果您喜欢不同类型的提示符,我建议您查看该文档。

相关问题