Improve PowerShell prompt for older version

This commit is contained in:
Anthony Rose 2023-03-19 22:38:03 +00:00
parent c05031356d
commit 5680247eff

View file

@ -4,18 +4,22 @@
# C:\Users\USERNAME\Documents\PowerShell\Microsoft.PowerShell_profile.ps1 # C:\Users\USERNAME\Documents\PowerShell\Microsoft.PowerShell_profile.ps1
function Prompt { function Prompt {
if ($IsWindows -and $PSVersionTable.PSVersion -gt [System.Version]"6.0") { if ($IsWindows -or ($env:OS -eq "Windows_NT")) {
[string]$monoPrompt = ""
$currentPrincipal = New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent()) $currentPrincipal = New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())
if ($currentPrincipal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) { if ($currentPrincipal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
"`e[1m" + $env:USERNAME + "@" + $env:COMPUTERNAME.ToLower() + "# `e[0m" $monoPrompt = $env:USERNAME + "@" + $env:COMPUTERNAME.ToLower() + "# "
} else { } else {
"`e[1m" + $env:USERNAME + "@" + $env:COMPUTERNAME.ToLower() + "> `e[0m" $monoPrompt = $env:USERNAME + "@" + $env:COMPUTERNAME.ToLower() + "> "
} }
if ($PSVersionTable.PSVersion -gt [System.Version]"6.0") {
"`e[1m" + $monoPrompt + "`e[0m"
} else {
$monoPrompt
} }
elseif ($IsLinux) { } elseif ($IsLinux) {
"`e[1m" + $(id -un) + "@" + $(hostname -s) + "> `e[0m" "`e[1m" + $(id -un) + "@" + $(hostname -s) + "> `e[0m"
} } else {
else {
"PS> " "PS> "
} }
} }