Skip to content

Instantly share code, notes, and snippets.

@omniomi
Created May 23, 2018 19:49
Show Gist options
  • Select an option

  • Save omniomi/895dadedbb385642cf4f3309bd24f591 to your computer and use it in GitHub Desktop.

Select an option

Save omniomi/895dadedbb385642cf4f3309bd24f591 to your computer and use it in GitHub Desktop.
PowerShell Prompt
# Needs a Powerline Font (ie, DejaVu Sans Mono for Powerline).
# Needs Posh-Git module.
Import-Module Posh-Git
$currentPrincipal = New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())
if ($currentPrincipal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) { $Script:IsAdmin = $true }
function prompt {
if (((Get-Item $pwd).parent.parent.name)) {
$Path = '..\' + (Get-Item $pwd).parent.name + '\' + (Split-Path $pwd -Leaf)
} else {
$Path = $pwd.path
}
if($Script:IsAdmin) {
Write-Host " $([char]0xE0A2)" -ForegroundColor Black -BackgroundColor Green -NoNewline
Write-Host "$([char]0xE0B0) " -ForegroundColor Green -BackgroundColor Blue -NoNewline
}
Write-Host $MyInvocation.HistoryId -ForegroundColor Black -BackgroundColor Blue -NoNewline
Write-Host "$([char]0xE0B0) " -ForegroundColor Blue -BackgroundColor Cyan -NoNewline
Write-Host ($path).ToLower().TrimEnd('\') -ForegroundColor White -BackgroundColor Cyan -NoNewline
if ((Write-VcsStatus *>&1).Length -gt 0) {
Write-Host "$([char]0xE0B0)" -ForegroundColor Cyan -BackgroundColor DarkBlue -NoNewline
Write-Host (Write-VcsStatus) -NoNewline -BackgroundColor DarkBlue
Write-Host "$([char]0xE0B0)$("$([char]0xE0B1)" * $NestedPromptLevel)" -ForegroundColor DarkBlue -NoNewline
} else {
Write-Host "$([char]0xE0B0)$("$([char]0xE0B1)" * $NestedPromptLevel)" -ForegroundColor Cyan -NoNewline
}
' '
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment