Want to set the snazziest Windows Terminal colour scheme but not sure how to go about it?
Surely this is the top of everyone’s to-do list at this time of unprecedented calmness and serenity…
You could spend 5 minutes manually trying out the various options.
You could spend an hour hacking together a fairly rickety script that launches Windows Terminal with each of the built-in schemes.
Or you could let me do that for you and spend 20 seconds watching the results in video form:
Why not reward yourself for your time efficiency by spending 4 minutes 40 seconds scouring the Internet for Coronavirus morsels? Some suggested search terms:
- potato long term storage tips
- discourage social interaction clothing ideas obscene
- maximum safe potato consumption
- handshake alternatives obscene
- where buy potato minneapolis
Stay safe out there.
Here’s the code:
# Script that cycles through all Windows Terminal color schemes
# Depends on there being a profile called "PowerShell" with a colorScheme already set
param(
$profilesJsonPath = (Join-Path $env:LOCALAPPDATA 'Packages\Microsoft.WindowsTerminal_8wekyb3d8bbwe\LocalState\profiles.json'),
$defaultsJsonPath = (Join-Path $env:ProgramFiles 'WindowsApps\Microsoft.WindowsTerminal_0.10.761.0_x64__8wekyb3d8bbwe\defaults.json')
)
# Get all color schemes from default profiles file
$defaults = Get-Content $defaultsJsonPath | ConvertFrom-Json
$colorSchemes = $defaults.schemes.name
# Get profiles as text
$profiles = Get-Content $profilesJsonPath
# Fragile string stuff to find index of the colorScheme line in the PowerShell profile
# Easier than dealing with JSON + comments as objects?
$psNameIndex = ($profiles | Select-String '"name": "PowerShell",').LineNumber - 1
$sectionBoundaries = ($profiles | Select-String '},').LineNumber | ForEach-Object {$_ - 1} # Section delimited by '},'
$sectionStart = ($sectionBoundaries | Where-Object {$_ -lt $psNameIndex})[-1]
$sectionEnd = ($sectionBoundaries | Where-Object {$_ -gt $psNameIndex})[0]
$colorIndex = ($profiles[$sectionStart..$sectionEnd] | Select-String '"colorScheme":').LineNumber - 1 + $sectionStart
ForEach ($newScheme in $colorSchemes) {
# Regex to insert new scheme
$profiles[$colorIndex] = $profiles[$colorIndex] -replace '"colorScheme":.*[^,]' ,"`"colorScheme`": `"$newScheme`""
# Write out JSON
$profiles | Out-File $profilesJsonPath
# Launch Windows Terminal
$command = "Read-Host `"$newScheme`""
$arguments = @{
'FilePath' = 'wt.exe'
'ArgumentList' = "-p `"PowerShell`" pwsh.exe -Command $command"
'Wait' = $true
'WindowStyle' = 'Maximized'
}
Start-Process @arguments
}