From 5680247effaa9c83746bfa59e51dd788f2c4654e Mon Sep 17 00:00:00 2001 From: Anthony Perkins Date: Sun, 19 Mar 2023 22:38:03 +0000 Subject: [PATCH] Improve PowerShell prompt for older version --- .../files/Microsoft.PowerShell_profile.ps1 | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/roles/home-cli/files/Microsoft.PowerShell_profile.ps1 b/roles/home-cli/files/Microsoft.PowerShell_profile.ps1 index 4a98abf..a582f1c 100644 --- a/roles/home-cli/files/Microsoft.PowerShell_profile.ps1 +++ b/roles/home-cli/files/Microsoft.PowerShell_profile.ps1 @@ -4,18 +4,22 @@ # C:\Users\USERNAME\Documents\PowerShell\Microsoft.PowerShell_profile.ps1 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()) if ($currentPrincipal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) { - "`e[1m" + $env:USERNAME + "@" + $env:COMPUTERNAME.ToLower() + "# `e[0m" + $monoPrompt = $env:USERNAME + "@" + $env:COMPUTERNAME.ToLower() + "# " } else { - "`e[1m" + $env:USERNAME + "@" + $env:COMPUTERNAME.ToLower() + "> `e[0m" + $monoPrompt = $env:USERNAME + "@" + $env:COMPUTERNAME.ToLower() + "> " } - } - elseif ($IsLinux) { + if ($PSVersionTable.PSVersion -gt [System.Version]"6.0") { + "`e[1m" + $monoPrompt + "`e[0m" + } else { + $monoPrompt + } + } elseif ($IsLinux) { "`e[1m" + $(id -un) + "@" + $(hostname -s) + "> `e[0m" - } - else { + } else { "PS> " } }