所以我有这个 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 " "
}
}
