【发布时间】:2021-06-22 20:26:42
【问题描述】:
所以我有这个 PowerShell 配置文件,git 分支显示得很好,问题是当我在每个文件夹位置时,最后都显示 PS:
这是我的脚本(我真的不知道我是否在这里遗漏了什么,可能是else 路径):
function prompt {
$p = Split-Path -leaf -path (Get-Location)
$user = $env:UserName
$host.UI.RawUI.WindowTitle = "\" + $p + ">"
$host.UI.RawUI.ForegroundColor = "Blue"
if (Test-Path .git) {
$p = Split-Path -leaf -path (Get-Location)
git branch | ForEach-Object {
if ($_ -match "^\*(.*)") {
$branch = $matches[1] + " - "
Write-Host -NoNewLine $user -ForegroundColor Magenta
Write-Host -NoNewLine "@\"
Write-Host -NoNewLine $p -ForegroundColor Yellow
Write-Host -NoNewLine " - " -ForegroundColor DarkGreen
Write-Host -NoNewLine $branch -ForegroundColor DarkGreen
}
}
}
else {
Write-Host -NoNewLine $user -ForegroundColor Magenta
Write-Host -NoNewLine "@\"
Write-Host -NoNewLine $p -ForegroundColor Yellow
Write-Host -NoNewLine " "
}
}
【问题讨论】:
标签: windows powershell windows-terminal