Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Added support for Windows Terminal v0.11.1121.0 or newer #56

Draft
wants to merge 1 commit into
base: preview
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/ExportedFunctions/Find-MSTerminalFolder.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
3 changes: 1 addition & 2 deletions src/ExportedFunctions/Get-MSTerminalColorScheme.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/ExportedFunctions/Get-MSTerminalProfile.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function Get-MSTerminalProfile {
return
}

$ProfilesJson = Join-Path $Path "profiles.json"
$ProfilesJson = DetectTerminalConfigFile

ReadMSTerminalProfileJson $ProfilesJson | ForEach-Object {
$_.Profiles
Expand Down
3 changes: 1 addition & 2 deletions src/ExportedFunctions/Get-MSTerminalSetting.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
3 changes: 1 addition & 2 deletions src/ExportedFunctions/New-MSTerminalColorScheme.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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")) {
Expand Down
3 changes: 1 addition & 2 deletions src/ExportedFunctions/New-MSTerminalProfile.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
3 changes: 1 addition & 2 deletions src/ExportedFunctions/Remove-MSTerminalColorScheme.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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 = @()
}
Expand Down
3 changes: 1 addition & 2 deletions src/ExportedFunctions/Remove-MSTerminalProfile.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ function Remove-MSTerminalProfile {
$InputObject
)
begin {
$Path = Find-MSTerminalFolder
$SettingsPath = Join-Path $Path "profiles.json"
$SettingsPath = DetectTerminalConfigFile
$Settings = ReadMSTerminalProfileJson $SettingsPath
$ProfilesToRemove = @()
}
Expand Down
3 changes: 1 addition & 2 deletions src/ExportedFunctions/Set-MSTerminalProfile.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
3 changes: 1 addition & 2 deletions src/ExportedFunctions/Set-MSTerminalSetting.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
21 changes: 21 additions & 0 deletions src/InternalFunctions/DetectTerminalConfigFile.ps1
Original file line number Diff line number Diff line change
@@ -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
}