大家好,我是Git和Hg的忠实粉丝,在许多项目中都需要使用它们两个。目前我使用的是Posh-Hg,这是一个PowerShell插件,可以将当前分支和未提交的更改显示在PowerShell中。类似地,Posh-Git也是一样的,只不过是用于Git的。是否有人成功地让这两个PowerShell脚本很好地协同工作呢?
大家好,我是Git和Hg的忠实粉丝,在许多项目中都需要使用它们两个。目前我使用的是Posh-Hg,这是一个PowerShell插件,可以将当前分支和未提交的更改显示在PowerShell中。类似地,Posh-Git也是一样的,只不过是用于Git的。是否有人成功地让这两个PowerShell脚本很好地协同工作呢?
试着在你的个人资料脚本中使用这个:
function isCurrentDirectoryARepository($type) {
if ((Test-Path $type) -eq $TRUE) {
return $TRUE
}
# Test within parent dirs
$checkIn = (Get-Item .).parent
while ($checkIn -ne $NULL) {
$pathToTest = $checkIn.fullname + '/' + $type;
if ((Test-Path $pathToTest) -eq $TRUE) {
return $TRUE
} else {
$checkIn = $checkIn.parent
}
}
return $FALSE
}
# Posh-Hg and Posh-git prompt
. $ProfileRoot\Modules\posh-hg\profile.example.ps1
. $ProfileRoot\Modules\posh-git\profile.example.ps1
function prompt(){
# Reset color, which can be messed up by Enable-GitColors
$Host.UI.RawUI.ForegroundColor = $GitPromptSettings.DefaultForegroundColor
Write-Host($pwd) -nonewline
if (isCurrentDirectoryARepository(".git")) {
# Git Prompt
$Global:GitStatus = Get-GitStatus
Write-GitStatus $GitStatus
} elseif (isCurrentDirectoryARepository(".hg")) {
# Mercurial Prompt
$Global:HgStatus = Get-HgStatus
Write-HgStatus $HgStatus
}
return "> "
}
请注意,该问题现已得到解决。假设您安装了最新版本的Posh-Hg和Posh-Git,您的配置文件应该只包含它们。
# Posh-Hg and Posh-git prompt
. $ProfileRoot\Modules\posh-hg\profile.example.ps1
. $ProfileRoot\Modules\posh-git\profile.example.ps1
提示 - 有一个名为Posh-GIT-HG的巧克力软件包,正如上面的答案所建议的那样,但它还具有潜在的好处,可以与最新版本的posh-git和posh-hg保持同步。
Write-HgStatus $HgStatus
这一行为Write-VcsStatus $HgStatus
,因为函数名称已经改变了。 - Alex HumphreyWrite-VcsStatus
被引入到 posh-hg 和 posh-git 中,以明确支持共存。如果您拥有两者的最新版本,则应该能够只导入两个示例配置文件而不需要上述代码。 - Sam