Posh-Git和Posh-Hg可以一起使用吗?

13

大家好,我是Git和Hg的忠实粉丝,在许多项目中都需要使用它们两个。目前我使用的是Posh-Hg,这是一个PowerShell插件,可以将当前分支和未提交的更改显示在PowerShell中。类似地,Posh-Git也是一样的,只不过是用于Git的。是否有人成功地让这两个PowerShell脚本很好地协同工作呢?

http://poshhg.codeplex.com/

http://github.com/dahlbyk/posh-git alt text

3个回答

19

试着在你的个人资料脚本中使用这个:

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 "> "
}

今晚我会尝试一下,看看它是否有效。非常感谢您尝试回答这个问题。 - Khalid Abuhakmeh
+1 很棒的回答。不过,我刚刚拉取了最新版本的posh-hg,并且不得不修改Write-HgStatus $HgStatus这一行为Write-VcsStatus $HgStatus,因为函数名称已经改变了。 - Alex Humphrey
2
Write-VcsStatus 被引入到 posh-hg 和 posh-git 中,以明确支持共存。如果您拥有两者的最新版本,则应该能够只导入两个示例配置文件而不需要上述代码。 - Sam

11

请注意,该问题现已得到解决。假设您安装了最新版本的Posh-Hg和Posh-Git,您的配置文件应该只包含它们。

# Posh-Hg and Posh-git prompt
. $ProfileRoot\Modules\posh-hg\profile.example.ps1
. $ProfileRoot\Modules\posh-git\profile.example.ps1

2

提示 - 有一个名为Posh-GIT-HG的巧克力软件包,正如上面的答案所建议的那样,但它还具有潜在的好处,可以与最新版本的posh-git和posh-hg保持同步。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接