Handle PowerShell 5 on Windows

This commit is contained in:
Anthony Rose 2022-03-02 12:49:23 +00:00
parent 0c957ffff6
commit d61938bdcd

View file

@ -4,7 +4,7 @@
# C:\Users\USERNAME\Documents\PowerShell\Microsoft.PowerShell_profile.ps1
function Prompt {
if ($IsWindows) {
if ($IsWindows -or $PSVersionTable.PSVersion.Major -le 5) {
$currentPrincipal = New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())
if ($currentPrincipal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
$env:USERNAME + "@" + $env:COMPUTERNAME.ToLower() + "# "
@ -35,6 +35,7 @@ Set-PSReadLineKeyHandler -Chord Ctrl+RightArrow -Function ForwardWord
Set-PSReadLineKeyHandler -Chord Ctrl+Backspace -Function BackwardKillWord
Set-PSReadLineKeyHandler -Chord Ctrl+Delete -Function KillWord
if ($PSVersionTable.PSVersion.Major -ge 7) {
$AnsiReset = "`e[0m"
Set-PSReadLineOption -Colors @{
Default = $AnsiReset;
@ -54,3 +55,4 @@ Set-PSReadLineOption -Colors @{
Type = $AnsiReset;
Variable = $AnsiReset;
}
}