Skip to content

Instantly share code, notes, and snippets.

@SugarDarius
Last active March 28, 2020 03:45
Show Gist options
  • Save SugarDarius/82ee4c19a9b870cc74b1cd0dbbe2a390 to your computer and use it in GitHub Desktop.
Save SugarDarius/82ee4c19a9b870cc74b1cd0dbbe2a390 to your computer and use it in GitHub Desktop.
Customized PowerShell Prompt (Windows Terminal and classic PowerShell app)
# use Install-Module -Name Emojis
Import-Module -Name Emojis;
function Test-Administrator {
$user = [Security.Principal.WindowsIdentity]::GetCurrent();
(New-Object Security.Principal.WindowsPrincipal $user).isInRole([Security.Principal.WindowsBuiltinRole]::Administrator)
}
function prompt {
$realLASTEXITCODE = $LASTEXITCODE;
$openTime = (Get-Date -UFormat '%y/%m/%d %R').ToString();
$Host.UI.RawUI.WindowTitle = "PowerShell $ENV:USERNAME - $openTime";
if (Test-Administrator) {
Write-Host "(Admin) " -NoNewline -ForegroundColor White
}
Write-Host "$ENV:USERNAME@" -NoNewline -ForegroundColor DarkGray
Write-Host "$ENV:COMPUTERNAME -> " -NoNewline -ForegroundColor Magenta
Write-Host $($(Get-Location) -replace ($env:USERPROFILE).Replace('\','\\'), "~") -NoNewLine -ForegroundColor Cyan
$gitBranchName = ((git rev-parse --abbrev-ref HEAD) | Out-String).Trim();
if ($gitBranchName.Length -gt 0) {
Write-Host " | " -NoNewLine -ForegroundColor DarkGray;
Write-Host "$gitBranchName branch " -NoNewLine -ForegroundColor Gray;
$status = (git status --porcelain);
if ($status) {
Write-Host "(edited - $(Get-Emoji -Name WRENCH))" -NoNewLine -ForegroundColor DarkGray;
}
else {
Write-Host "(up to date - $(Get-Emoji -Name ROCKET))" -NoNewLine -ForegroundColor DarkGray;
}
}
Write-Host "";
Write-Host "=>" -NoNewLine -ForegroundColor Cyan;
$global:LASTEXITCODE = $realLASTEXITCODE;
return " ";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment