Only write VCS Status if we're in a git repo

In an effort to speed up the prompt we will only call write-vcsstatus if
there is a .git folder in the current or any parent path recursively.

As this function is called every new prompt line it needs to be as fast as
possible.
This commit is contained in:
Jack Bennett 2015-03-25 12:29:10 +00:00
parent 18fc5e37c7
commit c466698d6b

13
vendor/profile.ps1 vendored
View File

@ -14,13 +14,24 @@ try {
$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
function global:prompt {
$realLASTEXITCODE = $LASTEXITCODE
$Host.UI.RawUI.ForegroundColor = "White"
Write-Host $pwd.ProviderPath -NoNewLine -ForegroundColor Green
Write-VcsStatus
if($gitStatus){
checkGit($pwd.ProviderPath)
}
$global:LASTEXITCODE = $realLASTEXITCODE
Write-Host "`nλ" -NoNewLine -ForegroundColor "DarkGray"