From 7f8b26bd4bfc8002c305aa73a6f91da6448af55c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Janek=20Kr=C3=B6ger?= Date: Thu, 7 May 2020 21:22:14 +0200 Subject: [PATCH] Added support for v0.11.1121.0 or newer --- .../Find-MSTerminalFolder.ps1 | 2 +- .../Get-MSTerminalColorScheme.ps1 | 3 +-- .../Get-MSTerminalProfile.ps1 | 2 +- .../Get-MSTerminalSetting.ps1 | 3 +-- .../New-MSTerminalColorScheme.ps1 | 3 +-- .../New-MSTerminalProfile.ps1 | 3 +-- .../Remove-MSTerminalColorScheme.ps1 | 3 +-- .../Remove-MSTerminalProfile.ps1 | 3 +-- .../Set-MSTerminalProfile.ps1 | 3 +-- .../Set-MSTerminalSetting.ps1 | 3 +-- .../DetectTerminalConfigFile.ps1 | 21 +++++++++++++++++++ 11 files changed, 31 insertions(+), 18 deletions(-) create mode 100644 src/InternalFunctions/DetectTerminalConfigFile.ps1 diff --git a/src/ExportedFunctions/Find-MSTerminalFolder.ps1 b/src/ExportedFunctions/Find-MSTerminalFolder.ps1 index 13a25c9..937b6f8 100644 --- a/src/ExportedFunctions/Find-MSTerminalFolder.ps1 +++ b/src/ExportedFunctions/Find-MSTerminalFolder.ps1 @@ -20,7 +20,7 @@ function Find-MSTerminalFolder { if($FoundPath) { $FoundPath } else { - Write-Error "Unable to locate Terminal profiles.json file." -ErrorAction Stop + Write-Error "Unable to locate Terminal $(Split-Path (DetectTerminalConfigFile) -Leaf) file." -ErrorAction Stop } } } diff --git a/src/ExportedFunctions/Get-MSTerminalColorScheme.ps1 b/src/ExportedFunctions/Get-MSTerminalColorScheme.ps1 index b4ee9e6..d42fec9 100644 --- a/src/ExportedFunctions/Get-MSTerminalColorScheme.ps1 +++ b/src/ExportedFunctions/Get-MSTerminalColorScheme.ps1 @@ -2,8 +2,7 @@ function Get-MSTerminalColorScheme { param( $Name ) - $Path = Find-MSTerminalFolder - $SettingsPath = Join-Path $Path "profiles.json" + $SettingsPath = DetectTerminalConfigFile $Settings = ReadMSTerminalProfileJson $SettingsPath $Settings.Schemes | Where-Object { diff --git a/src/ExportedFunctions/Get-MSTerminalProfile.ps1 b/src/ExportedFunctions/Get-MSTerminalProfile.ps1 index 1313b97..4798c79 100644 --- a/src/ExportedFunctions/Get-MSTerminalProfile.ps1 +++ b/src/ExportedFunctions/Get-MSTerminalProfile.ps1 @@ -13,7 +13,7 @@ function Get-MSTerminalProfile { return } - $ProfilesJson = Join-Path $Path "profiles.json" + $ProfilesJson = DetectTerminalConfigFile ReadMSTerminalProfileJson $ProfilesJson | ForEach-Object { $_.Profiles diff --git a/src/ExportedFunctions/Get-MSTerminalSetting.ps1 b/src/ExportedFunctions/Get-MSTerminalSetting.ps1 index 83e5be9..716684b 100644 --- a/src/ExportedFunctions/Get-MSTerminalSetting.ps1 +++ b/src/ExportedFunctions/Get-MSTerminalSetting.ps1 @@ -2,8 +2,7 @@ function Get-MSTerminalSetting { param( [Switch]$Force ) - $Path = Find-MSTerminalFolder - $SettingsPath = Join-Path $Path "profiles.json" + $SettingsPath = DetectTerminalConfigFile $Settings = ReadMSTerminalProfileJson $SettingsPath if($Settings.Globals) { diff --git a/src/ExportedFunctions/New-MSTerminalColorScheme.ps1 b/src/ExportedFunctions/New-MSTerminalColorScheme.ps1 index a41d958..0b7ba8e 100644 --- a/src/ExportedFunctions/New-MSTerminalColorScheme.ps1 +++ b/src/ExportedFunctions/New-MSTerminalColorScheme.ps1 @@ -40,8 +40,7 @@ function New-MSTerminalColorScheme { [string]$yellow = "#C19C00" ) - $Path = Find-MSTerminalFolder - $SettingsPath = Join-Path $Path "profiles.json" + $SettingsPath = DetectTerminalConfigFile $Settings = ReadMSTerminalProfileJson $SettingsPath | ConvertPSObjectToHashtable if(!$Settings.Contains("schemes")) { diff --git a/src/ExportedFunctions/New-MSTerminalProfile.ps1 b/src/ExportedFunctions/New-MSTerminalProfile.ps1 index 9874286..4ce41ec 100644 --- a/src/ExportedFunctions/New-MSTerminalProfile.ps1 +++ b/src/ExportedFunctions/New-MSTerminalProfile.ps1 @@ -78,8 +78,7 @@ function New-MSTerminalProfile { #Arbitrary properties, no validation occurs here so use at your own risk! [HashTable]$ExtraSettings ) - $Path = Find-MSTerminalFolder - $SettingsPath = Join-Path $Path "profiles.json" + $SettingsPath = DetectTerminalConfigFile $Settings = ReadMSTerminalProfileJson $SettingsPath | ConvertPSObjectToHashtable if($Settings.Globals) { $Global = $Settings["globals"] diff --git a/src/ExportedFunctions/Remove-MSTerminalColorScheme.ps1 b/src/ExportedFunctions/Remove-MSTerminalColorScheme.ps1 index f90853a..abc58aa 100644 --- a/src/ExportedFunctions/Remove-MSTerminalColorScheme.ps1 +++ b/src/ExportedFunctions/Remove-MSTerminalColorScheme.ps1 @@ -5,8 +5,7 @@ function Remove-MSTerminalColorScheme { [string[]]$Name ) begin { - $Path = Find-MSTerminalFolder - $SettingsPath = Join-Path $Path "profiles.json" + $SettingsPath = DetectTerminalConfigFile $Settings = ReadMSTerminalProfileJson $SettingsPath $SchemesToRemove = @() } diff --git a/src/ExportedFunctions/Remove-MSTerminalProfile.ps1 b/src/ExportedFunctions/Remove-MSTerminalProfile.ps1 index 49f1e44..314ebb5 100644 --- a/src/ExportedFunctions/Remove-MSTerminalProfile.ps1 +++ b/src/ExportedFunctions/Remove-MSTerminalProfile.ps1 @@ -8,8 +8,7 @@ function Remove-MSTerminalProfile { $InputObject ) begin { - $Path = Find-MSTerminalFolder - $SettingsPath = Join-Path $Path "profiles.json" + $SettingsPath = DetectTerminalConfigFile $Settings = ReadMSTerminalProfileJson $SettingsPath $ProfilesToRemove = @() } diff --git a/src/ExportedFunctions/Set-MSTerminalProfile.ps1 b/src/ExportedFunctions/Set-MSTerminalProfile.ps1 index 70a343f..43cf4d3 100644 --- a/src/ExportedFunctions/Set-MSTerminalProfile.ps1 +++ b/src/ExportedFunctions/Set-MSTerminalProfile.ps1 @@ -83,8 +83,7 @@ function Set-MSTerminalProfile { [hashtable]$ExtraSettings ) begin { - $Path = Find-MSTerminalFolder - $SettingsPath = Join-Path $Path "profiles.json" + $SettingsPath = DetectTerminalConfigFile # Don't use -AsHashtable for 5.1 support $Settings = ReadMSTerminalProfileJson $SettingsPath | ConvertPSObjectToHashtable if($Settings.Globals) { diff --git a/src/ExportedFunctions/Set-MSTerminalSetting.ps1 b/src/ExportedFunctions/Set-MSTerminalSetting.ps1 index 2daa219..5c2e33a 100644 --- a/src/ExportedFunctions/Set-MSTerminalSetting.ps1 +++ b/src/ExportedFunctions/Set-MSTerminalSetting.ps1 @@ -29,8 +29,7 @@ function Set-MSTerminalSetting { [hashtable]$ExtraSettings = @{} ) - $Path = Find-MSTerminalFolder - $SettingsPath = Join-Path $Path "profiles.json" + $SettingsPath = DetectTerminalConfigFile # Don't use -AsHashtable for 5.1 support $Settings = ReadMSTerminalProfileJson $SettingsPath | ConvertPSObjectToHashtable if($Settings.Globals) { diff --git a/src/InternalFunctions/DetectTerminalConfigFile.ps1 b/src/InternalFunctions/DetectTerminalConfigFile.ps1 new file mode 100644 index 0000000..80d21c0 --- /dev/null +++ b/src/InternalFunctions/DetectTerminalConfigFile.ps1 @@ -0,0 +1,21 @@ +<# +.SYNOPSIS +This command will return the path to the right configuration file for Windows Terminal. +.NOTES +In version 0.11.1121.0 the configuration file for Windows Terminal (`profiles.json`) has been renamed to `settings.json`. +#> +function DetectTerminalConfigFile { + try { + $TerminalApp = Get-AppxPackage -Name Microsoft.WindowsTerminal + } catch { + throw "This only works if Windows Terminal is installed on this computer." + } + $Path = Find-MSTerminalFolder + if ($TerminalApp.Version -ge 0.11.1121.0) { + $SettingsPath = Join-Path $Path "settings.json" + } else { + $SettingsPath = Join-Path $Path "profiles.json" + } + + return $SettingsPath +} \ No newline at end of file