From 9d11d4a8762ff5d87034a083b09e4da08388ed73 Mon Sep 17 00:00:00 2001 From: Anthony Perkins Date: Wed, 2 Mar 2022 11:56:41 +0000 Subject: [PATCH] Improve PowerShell on Linux --- .../files/Microsoft.PowerShell_profile.ps1 | 43 +++++++++++++++---- 1 file changed, 34 insertions(+), 9 deletions(-) diff --git a/roles/home-cli/files/Microsoft.PowerShell_profile.ps1 b/roles/home-cli/files/Microsoft.PowerShell_profile.ps1 index d6c8711..7462ee3 100644 --- a/roles/home-cli/files/Microsoft.PowerShell_profile.ps1 +++ b/roles/home-cli/files/Microsoft.PowerShell_profile.ps1 @@ -4,11 +4,16 @@ # C:\Users\USERNAME\Documents\PowerShell\Microsoft.PowerShell_profile.ps1 function Prompt { - $currentPrincipal = New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent()) - if ($currentPrincipal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) { - $env:USERNAME + "@" + $env:COMPUTERNAME.ToLower() + "# " - } else { - $env:USERNAME + "@" + $env:COMPUTERNAME.ToLower() + "> " + if ($IsWindows) { + $currentPrincipal = New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent()) + if ($currentPrincipal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) { + $env:USERNAME + "@" + $env:COMPUTERNAME.ToLower() + "# " + } else { + $env:USERNAME + "@" + $env:COMPUTERNAME.ToLower() + "> " + } + } + elseif ($IsLinux) { + "`e[1m" + $(id -un) + "@" + $(hostname -s) + "> `e[0m" } } @@ -17,15 +22,35 @@ Set-PSReadlineOption -BellStyle None Set-PSReadlineOption -EditMode Emacs Set-PSReadlineKeyHandler -Key Tab -Function Complete Set-PSReadLineKeyHandler -Key UpArrow -ScriptBlock { - [Microsoft.PowerShell.PSConsoleReadLine]::HistorySearchBackward() - [Microsoft.PowerShell.PSConsoleReadLine]::EndOfLine() + [Microsoft.PowerShell.PSConsoleReadLine]::HistorySearchBackward() + [Microsoft.PowerShell.PSConsoleReadLine]::EndOfLine() } Set-PSReadLineKeyHandler -Key DownArrow -ScriptBlock { - [Microsoft.PowerShell.PSConsoleReadLine]::HistorySearchForward() - [Microsoft.PowerShell.PSConsoleReadLine]::EndOfLine() + [Microsoft.PowerShell.PSConsoleReadLine]::HistorySearchForward() + [Microsoft.PowerShell.PSConsoleReadLine]::EndOfLine() } Set-PSReadLineKeyHandler -Chord Shift+Spacebar -Function SelfInsert Set-PSReadLineKeyHandler -Chord Ctrl+LeftArrow -Function BackwardWord Set-PSReadLineKeyHandler -Chord Ctrl+RightArrow -Function ForwardWord Set-PSReadLineKeyHandler -Chord Ctrl+Backspace -Function BackwardKillWord Set-PSReadLineKeyHandler -Chord Ctrl+Delete -Function KillWord + +$AnsiReset = "`e[0m" +Set-PSReadLineOption -Colors @{ + Default = $AnsiReset; + Command = $AnsiReset; + Comment = $AnsiReset; + ContinuationPrompt = $AnsiReset; + Emphasis = $AnsiReset; + Error = $AnsiReset; + InlinePrediction = $AnsiReset; + Keyword = $AnsiReset; + Member = $AnsiReset; + Number = $AnsiReset; + Operator = $AnsiReset; + Parameter = $AnsiReset; + Selection = $AnsiReset; + String = $AnsiReset; + Type = $AnsiReset; + Variable = $AnsiReset; +}