• Home
  • About
  • Posts
  • Projects
  • Tindie Shop

Previous post Next post Back to top Share post

Familiar PowerShell prompt (with Posh-Git)

ZiggyTheHamster
2013-05-04
articles
tip, windows

Here is the Windows PowerShell version of the Bash prompt I use:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
function prompt {
$realLASTEXITCODE = $LASTEXITCODE

# Reset color, which can be messed up by Enable-GitColors
$Host.UI.RawUI.ForegroundColor = $GitPromptSettings.DefaultForegroundColor

$currentPrincipal = New-Object Security.Principal.WindowsPrincipal( [Security.Principal.WindowsIdentity]::GetCurrent() )
& {
if ($currentPrincipal.IsInRole( [Security.Principal.WindowsBuiltInRole]::Administrator ))
{
Write-Host($env:username) -f red -nonewline
Write-Host("@") -f red -nonewline
Write-Host($env:computername) -f red -nonewline
Write-Host(":") -nonewline
Write-Host($pwd.ProviderPath) -f blue -nonewline

Write-VcsStatus

Write-Host('#') -nonewline
} else {
Write-Host($env:username) -f green -nonewline
Write-Host("@") -f green -nonewline
Write-Host($env:computername) -f green -nonewline
Write-Host(":") -nonewline
Write-Host($pwd.ProviderPath) -f blue -nonewline

Write-VcsStatus

Write-Host('$') -nonewline
}
}

$global:LASTEXITCODE = $realLASTEXITCODE
return " "
}
  • Home
  • About
  • Posts
  • Projects
  • Tindie Shop
Menu  TOC  Share  Top
Copyright © 2001-2026 ZiggyTheHamster
  • Home
  • About
  • Posts
  • Projects
  • Tindie Shop
Powered by FreeBSDAnything But ChromeZiggy the Hamster.shVisual Studio CodeDay 2Trans They/ThemBi Pride