From 513c6454361298a1ba30fc1ac0aa7997e1a53b3f Mon Sep 17 00:00:00 2001 From: Anthony Perkins Date: Tue, 2 Jul 2024 09:14:07 +0100 Subject: [PATCH] Check for $PSStyle variable --- .../files/Microsoft.PowerShell_profile.ps1 | 76 ++++++++++--------- 1 file changed, 39 insertions(+), 37 deletions(-) diff --git a/roles/home-cli/files/Microsoft.PowerShell_profile.ps1 b/roles/home-cli/files/Microsoft.PowerShell_profile.ps1 index 35c9e15..3e13281 100644 --- a/roles/home-cli/files/Microsoft.PowerShell_profile.ps1 +++ b/roles/home-cli/files/Microsoft.PowerShell_profile.ps1 @@ -115,44 +115,46 @@ Set-PSReadLineKeyHandler -Chord Shift+Spacebar -Function SelfInsert # Colours for a light-coloured terminal. # https://learn.microsoft.com/en-us/powershell/scripting/learn/shell/using-light-theme?view=powershell-7.2 -$ISETheme = @{ - Command = $PSStyle.Foreground.FromRGB(0x0000FF) - Comment = $PSStyle.Foreground.FromRGB(0x006400) - ContinuationPrompt = $PSStyle.Foreground.FromRGB(0x0000FF) - Default = $PSStyle.Foreground.FromRGB(0x0000FF) - Emphasis = $PSStyle.Foreground.FromRGB(0x287BF0) - Error = $PSStyle.Foreground.FromRGB(0xE50000) - InlinePrediction = $PSStyle.Foreground.FromRGB(0x93A1A1) - Keyword = $PSStyle.Foreground.FromRGB(0x00008b) - #ListPrediction = $PSStyle.Foreground.FromRGB(0x06DE00) - Member = $PSStyle.Foreground.FromRGB(0x000000) - Number = $PSStyle.Foreground.FromRGB(0x800080) - Operator = $PSStyle.Foreground.FromRGB(0x757575) - Parameter = $PSStyle.Foreground.FromRGB(0x000080) - String = $PSStyle.Foreground.FromRGB(0x8b0000) - Type = $PSStyle.Foreground.FromRGB(0x008080) - Variable = $PSStyle.Foreground.FromRGB(0xff4500) - #ListPredictionSelected = $PSStyle.Background.FromRGB(0x93A1A1) - Selection = $PSStyle.Background.FromRGB(0x00BFFF) +if ($null -ne $PSStyle) { + $ISETheme = @{ + Command = $PSStyle.Foreground.FromRGB(0x0000FF) + Comment = $PSStyle.Foreground.FromRGB(0x006400) + ContinuationPrompt = $PSStyle.Foreground.FromRGB(0x0000FF) + Default = $PSStyle.Foreground.FromRGB(0x0000FF) + Emphasis = $PSStyle.Foreground.FromRGB(0x287BF0) + Error = $PSStyle.Foreground.FromRGB(0xE50000) + InlinePrediction = $PSStyle.Foreground.FromRGB(0x93A1A1) + Keyword = $PSStyle.Foreground.FromRGB(0x00008b) + #ListPrediction = $PSStyle.Foreground.FromRGB(0x06DE00) + Member = $PSStyle.Foreground.FromRGB(0x000000) + Number = $PSStyle.Foreground.FromRGB(0x800080) + Operator = $PSStyle.Foreground.FromRGB(0x757575) + Parameter = $PSStyle.Foreground.FromRGB(0x000080) + String = $PSStyle.Foreground.FromRGB(0x8b0000) + Type = $PSStyle.Foreground.FromRGB(0x008080) + Variable = $PSStyle.Foreground.FromRGB(0xff4500) + #ListPredictionSelected = $PSStyle.Background.FromRGB(0x93A1A1) + Selection = $PSStyle.Background.FromRGB(0x00BFFF) + } + Set-PSReadLineOption -Colors $ISETheme + $PSStyle.Formatting.FormatAccent = "`e[32m" + $PSStyle.Formatting.TableHeader = "`e[32m" + $PSStyle.Formatting.ErrorAccent = "`e[36m" + $PSStyle.Formatting.Error = "`e[31m" + $PSStyle.Formatting.Warning = "`e[33m" + $PSStyle.Formatting.Verbose = "`e[33m" + $PSStyle.Formatting.Debug = "`e[33m" + $PSStyle.Progress.Style = "`e[33m" + $PSStyle.FileInfo.Directory = $PSStyle.Background.FromRgb(0x2f6aff) + + $PSStyle.Foreground.BrightWhite + $PSStyle.FileInfo.SymbolicLink = "`e[36m" + $PSStyle.FileInfo.Executable = "`e[95m" + $PSStyle.FileInfo.Extension['.ps1'] = "`e[36m" + $PSStyle.FileInfo.Extension['.ps1xml'] = "`e[36m" + $PSStyle.FileInfo.Extension['.psd1'] = "`e[36m" + $PSStyle.FileInfo.Extension['.psm1'] = "`e[36m" + Remove-Variable ISETheme } -Set-PSReadLineOption -Colors $ISETheme -$PSStyle.Formatting.FormatAccent = "`e[32m" -$PSStyle.Formatting.TableHeader = "`e[32m" -$PSStyle.Formatting.ErrorAccent = "`e[36m" -$PSStyle.Formatting.Error = "`e[31m" -$PSStyle.Formatting.Warning = "`e[33m" -$PSStyle.Formatting.Verbose = "`e[33m" -$PSStyle.Formatting.Debug = "`e[33m" -$PSStyle.Progress.Style = "`e[33m" -$PSStyle.FileInfo.Directory = $PSStyle.Background.FromRgb(0x2f6aff) + - $PSStyle.Foreground.BrightWhite -$PSStyle.FileInfo.SymbolicLink = "`e[36m" -$PSStyle.FileInfo.Executable = "`e[95m" -$PSStyle.FileInfo.Extension['.ps1'] = "`e[36m" -$PSStyle.FileInfo.Extension['.ps1xml'] = "`e[36m" -$PSStyle.FileInfo.Extension['.psd1'] = "`e[36m" -$PSStyle.FileInfo.Extension['.psm1'] = "`e[36m" -Remove-Variable ISETheme # Keep this at the end. if (Test-Path "$PSScriptRoot/local.ps1") {