Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save zooxmusic/8033c0bc8d417dc8b2bcf94dee29c43b to your computer and use it in GitHub Desktop.
Save zooxmusic/8033c0bc8d417dc8b2bcf94dee29c43b to your computer and use it in GitHub Desktop.
Script to install git Colors for the command window
# http://serverfault.com/questions/95431
function Test-Administrator {
$user = [Security.Principal.WindowsIdentity]::GetCurrent();
(New-Object Security.Principal.WindowsPrincipal $user).IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)
}
function prompt {
# https://github.com/dahlbyk/posh-git/wiki/Customizing-Your-PowerShell-Prompt
$origLastExitCode = $LastExitCode
Write-VcsStatus
if (Test-Administrator) { # if elevated
Write-Host "(Elevated) " -NoNewline -ForegroundColor White
}
Write-Host "$env:USERNAME@" -NoNewline -ForegroundColor DarkYellow
Write-Host "$env:COMPUTERNAME" -NoNewline -ForegroundColor Magenta
Write-Host " : " -NoNewline -ForegroundColor DarkGray
$curPath = $ExecutionContext.SessionState.Path.CurrentLocation.Path
if ($curPath.ToLower().StartsWith($Home.ToLower()))
{
$curPath = "~" + $curPath.SubString($Home.Length)
}
Write-Host $curPath -NoNewline -ForegroundColor Blue
Write-Host " : " -NoNewline -ForegroundColor DarkGray
Write-Host (Get-Date -Format G) -NoNewline -ForegroundColor DarkMagenta
Write-Host " : " -NoNewline -ForegroundColor DarkGray
$LastExitCode = $origLastExitCode
"`n$('>' * ($nestedPromptLevel + 1)) "
}
Import-Module posh-git
$global:GitPromptSettings.BeforeText = '['
$global:GitPromptSettings.AfterText = '] '
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment