Skip to content

Instantly share code, notes, and snippets.

@cbilson
Created July 8, 2015 16:15
Show Gist options
  • Save cbilson/3ce2288041d6f76ff2c4 to your computer and use it in GitHub Desktop.
Save cbilson/3ce2288041d6f76ff2c4 to your computer and use it in GitHub Desktop.
Powershell+Posh-Git prompt function that does not hang ConEmu
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