-
-
Save Erisa/9c170dd20af7fcff0f2a617630f70dfa to your computer and use it in GitHub Desktop.
Hot powershell prompt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function prompt { | |
$lastCmdFailed = !$?; | |
$asciiSymbols = $true # If your terminal doesn't display unicode properly | |
# Cause $IsWindows and shit doesn't exist on current Windows Powershell version | |
$windows = $IsWindows -or $env:OS -eq 'Windows_NT' | |
if ($windows) { | |
$admin = [bool](([System.Security.Principal.WindowsIdentity]::GetCurrent()).groups -match 'S-1-5-32-544') | |
$name = $env:UserName | |
} else { | |
$admin = (id -u) -eq 0 | |
$name = id -un | |
} | |
$isHome = (Get-Location).Path.StartsWith($HOME) | |
$time = (Get-Date).ToString('HH:mm') | |
$path = (Get-Location).Path | |
$hostname = hostname | |
if ($isHome) { $path = $path.Replace($HOME, '~') } | |
$esc = [char]27 | |
$r = "$esc[0m" | |
$symbols = @{ | |
pathOpen = if (!$asciiSymbols) { "⌈" } else { "[" }; | |
pathClose = if (!$asciiSymbols) { "⌋" } else { "]" }; | |
timeOpen = if (!$asciiSymbols) { "⌊" } else { "[" }; | |
timeClose = if (!$asciiSymbols) { "⌉" } else { "]" }; | |
admin = if (!$asciiSymbols) { "⚡" } else { "#" }; | |
prompt = if (!$asciiSymbols) { "〉" } else { ">" }; | |
} | |
$colors = @{ | |
separator = "$esc[34m"; | |
location = "$esc[32m"; | |
time = "$esc[33m"; | |
admin = "$esc[32m"; | |
name = "$esc[95m"; | |
error = "$esc[1;31m" | |
} | |
$prompt = @( | |
"" | |
@( | |
"$($colors.separator)$($symbols.pathOpen) $($colors.name)$name@$hostname $($colors.location)$path $($colors.separator)$($symbols.pathClose)" | |
"$($symbols.timeOpen) $($colors.time)$time $($colors.separator)$($symbols.timeClose)" | |
" $(if ($admin) { "$($colors.admin)$($symbols.admin)" } else { '' })" | |
) -join "" | |
"$( | |
if ($lastCmdFailed) { $colors.error } else { $colors.separator } | |
)$($symbols.prompt)$r " | |
) | |
$prompt -join "`n" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment