Created
July 8, 2015 16:15
-
-
Save cbilson/3ce2288041d6f76ff2c4 to your computer and use it in GitHub Desktop.
Powershell+Posh-Git prompt function that does not hang ConEmu
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Test-IsAdmin { | |
$currentUser = [Security.Principal.WindowsIdentity]::GetCurrent() | |
$principal = new-object Security.Principal.WindowsPrincipal($currentUser) | |
$principal.IsInRole("Administrators") | |
} | |
$global:IsCurrentUserAdministrator = Test-IsAdmin | |
function global:prompt { | |
$realLastExitCode = $LastExitCode | |
if (Get-Module Posh-Git) { | |
$Host.UI.RawUI.ForegroundColor = $GitPromptSettings.DefaultForegroundColor | |
Write-Host $pwd.ProviderPath -NoNewLine | |
Write-VcsStatus | |
Write-Host | |
Enable-GitColors | |
} else { | |
$Host.UI.RawUI.ForegroundColor = 'Cyan' | |
Write-Host $pwd.ProviderPath | |
} | |
if ($global:IsCurrentUserAdministrator) { | |
$Host.UI.RawUI.ForegroundColor = 'Red' | |
Write-Host '***Administrator*** $' -NoNewLine | |
} else { | |
$Host.UI.RawUI.ForegroundColor = 'Yellow' | |
Write-Host '>' -NoNewline | |
} | |
$Host.UI.RawUI.ForegroundColor = 'Gray' | |
$global:LastExitCode = $realLastExitCode | |
return ' ' | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment