Merge pull request #440 from Jackbennett/proper-git-check

git and Posh-git check
This commit is contained in:
Martin Kemp 2015-03-25 15:07:51 +00:00
commit 520e7cfc0d

26
vendor/profile.ps1 vendored
View File

@ -5,13 +5,33 @@ if( -not $env:PSModulePath.Contains($CmderModulePath) ){
$env:PSModulePath = $env:PSModulePath.Insert(0, "$CmderModulePath;") $env:PSModulePath = $env:PSModulePath.Insert(0, "$CmderModulePath;")
} }
try {
Get-command -Name "git" -ErrorAction Stop >$null
Import-Module -Name "posh-git" -ErrorAction Stop >$null
$gitStatus = $true
} catch {
Write-Warning "Missing git support"
$gitStatus = $false
}
function checkGit($Path) {
if (Test-Path -Path (Join-Path $Path '.git/') ) {
Write-VcsStatus
return
}
$SplitPath = split-path $path
if ($SplitPath) {
checkGit($SplitPath)
}
}
# Set up a Cmder prompt, adding the git prompt parts inside git repos # Set up a Cmder prompt, adding the git prompt parts inside git repos
function global:prompt { function global:prompt {
$realLASTEXITCODE = $LASTEXITCODE $realLASTEXITCODE = $LASTEXITCODE
$Host.UI.RawUI.ForegroundColor = "White" $Host.UI.RawUI.ForegroundColor = "White"
Write-Host $pwd.ProviderPath -NoNewLine -ForegroundColor Green Write-Host $pwd.ProviderPath -NoNewLine -ForegroundColor Green
if (Get-Module posh-git) { if($gitStatus){
Write-VcsStatus checkGit($pwd.ProviderPath)
} }
$global:LASTEXITCODE = $realLASTEXITCODE $global:LASTEXITCODE = $realLASTEXITCODE
Write-Host "`nλ" -NoNewLine -ForegroundColor "DarkGray" Write-Host "`nλ" -NoNewLine -ForegroundColor "DarkGray"
@ -19,7 +39,7 @@ function global:prompt {
} }
# Load special features come from posh-git # Load special features come from posh-git
if (Get-Module posh-git) { if ($gitStatus) {
Enable-GitColors Enable-GitColors
Start-SshAgent -Quiet Start-SshAgent -Quiet
} }