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
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 "> "
}
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With