Improve PowerShell on Linux

This commit is contained in:
Anthony Rose 2022-03-02 11:56:41 +00:00
parent 2597888258
commit 9d11d4a876

View file

@ -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;
}