Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Posh-Git and Posh-Hg Together?

Hello I am a big fan of Git and Hg and have to use them both on many projects. I currently use Posh-Hg, which is a powershell plugin that places the current branch and outstanding commit right in your powershell. Posh-Git operates in a similar manner except for Git. Has anyone successfully gotten the two powershell scripts to play nice together?

http://poshhg.codeplex.com/

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

like image 300
Khalid Abuhakmeh Avatar asked Dec 21 '10 14:12

Khalid Abuhakmeh


3 Answers

Try this one in your profile script:

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 "> "
}
like image 117
rodpl Avatar answered Nov 11 '22 17:11

rodpl


Please note, that issue is now fixed. Assuming that you have last versions of the Posh-Hg and Posh-Git, your profile should include only.

# Posh-Hg and Posh-git prompt
. $ProfileRoot\Modules\posh-hg\profile.example.ps1
. $ProfileRoot\Modules\posh-git\profile.example.ps1
like image 21
Mike Chaliy Avatar answered Nov 11 '22 17:11

Mike Chaliy


FYI - there's a sweet Chocolatey package called Posh-GIT-HG that does exactly what the answer above suggests, but has the added benefit of potentially staying in sync with the latest versions of posh-git and posh-hg.

like image 22
twistedstream Avatar answered Nov 11 '22 19:11

twistedstream