Handle PowerShell 5 on Windows
This commit is contained in:
parent
0c957ffff6
commit
d61938bdcd
1 changed files with 20 additions and 18 deletions
|
@ -4,7 +4,7 @@
|
||||||
# C:\Users\USERNAME\Documents\PowerShell\Microsoft.PowerShell_profile.ps1
|
# C:\Users\USERNAME\Documents\PowerShell\Microsoft.PowerShell_profile.ps1
|
||||||
|
|
||||||
function Prompt {
|
function Prompt {
|
||||||
if ($IsWindows) {
|
if ($IsWindows -or $PSVersionTable.PSVersion.Major -le 5) {
|
||||||
$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)) {
|
||||||
$env:USERNAME + "@" + $env:COMPUTERNAME.ToLower() + "# "
|
$env:USERNAME + "@" + $env:COMPUTERNAME.ToLower() + "# "
|
||||||
|
@ -35,22 +35,24 @@ Set-PSReadLineKeyHandler -Chord Ctrl+RightArrow -Function ForwardWord
|
||||||
Set-PSReadLineKeyHandler -Chord Ctrl+Backspace -Function BackwardKillWord
|
Set-PSReadLineKeyHandler -Chord Ctrl+Backspace -Function BackwardKillWord
|
||||||
Set-PSReadLineKeyHandler -Chord Ctrl+Delete -Function KillWord
|
Set-PSReadLineKeyHandler -Chord Ctrl+Delete -Function KillWord
|
||||||
|
|
||||||
$AnsiReset = "`e[0m"
|
if ($PSVersionTable.PSVersion.Major -ge 7) {
|
||||||
Set-PSReadLineOption -Colors @{
|
$AnsiReset = "`e[0m"
|
||||||
|
Set-PSReadLineOption -Colors @{
|
||||||
Default = $AnsiReset;
|
Default = $AnsiReset;
|
||||||
Command = $AnsiReset;
|
Command = $AnsiReset;
|
||||||
Comment = $AnsiReset;
|
Comment = $AnsiReset;
|
||||||
ContinuationPrompt = $AnsiReset;
|
ContinuationPrompt = $AnsiReset;
|
||||||
Emphasis = $AnsiReset;
|
Emphasis = $AnsiReset;
|
||||||
Error = $AnsiReset;
|
Error = $AnsiReset;
|
||||||
InlinePrediction = $AnsiReset;
|
InlinePrediction = $AnsiReset;
|
||||||
Keyword = $AnsiReset;
|
Keyword = $AnsiReset;
|
||||||
Member = $AnsiReset;
|
Member = $AnsiReset;
|
||||||
Number = $AnsiReset;
|
Number = $AnsiReset;
|
||||||
Operator = $AnsiReset;
|
Operator = $AnsiReset;
|
||||||
Parameter = $AnsiReset;
|
Parameter = $AnsiReset;
|
||||||
Selection = $AnsiReset;
|
Selection = $AnsiReset;
|
||||||
String = $AnsiReset;
|
String = $AnsiReset;
|
||||||
Type = $AnsiReset;
|
Type = $AnsiReset;
|
||||||
Variable = $AnsiReset;
|
Variable = $AnsiReset;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue