这是我的 ConsoleZ powershell,我也想拥有一个 posh-git 环境,但它不起作用。
这行代码位于 Microsoft PowerShell 配置文件中
Write-Host "Setting up GitHub Environment"
. (Resolve-Path "$env:LOCALAPPDATA\GitHub\shell.ps1")
Write-Host "Setting up Posh-Git"
. (Resolve-Path "$env:github_posh_git\profile.example.ps1")
function prompt {
$p = Split-Path -leaf -path (Get-Location)
"$p> "
}
我已经尝试了几次,posh-git 不会集成到我的 consoleZ 上。
问题是在将所有需要的脚本放入 $profile 之后它不会运行 posh-git。
我不能让它变成这样。
更新
Burt_Harris 的评论是对的,这是因为提示功能弄乱了 posh_git,现在我的问题是如何让这 2 个功能正常工作?
更新 2
我的脚本结合了两个提示功能。只要给我 PS> 而不是文件夹目录>
# Prompt for shortened link on command line
function myPrompt {
$p = Split-Path -leaf -path (Get-Location)
"$p> "
}
$myPrompt = $function:myPrompt
# Set up a simple prompt, adding the git prompt parts inside git repos
function posh_gitPrompt {
$realLASTEXITCODE = $LASTEXITCODE
Write-Host($pwd.ProviderPath) -nonewline
Write-VcsStatus
$global:LASTEXITCODE = $realLASTEXITCODE
return "> "
}
# Combine myPrompt & posh_gitPrompt
function global:prompt {
"myPrompt`n$(&$posh_gitPrompt)"
}
解决方案
而不是使用这个
Write-Host($pwd.ProviderPath) -nonewline
在 posh_git 示例配置文件中,我将其修改为
Write-Host(Split-Path -leaf $pwd.ProviderPath) -nonewline
这成功了,不需要制作另一个功能。