Back to Terminal

ITerm2 schemes for the Terminal

src/tools/schemes-fragment/import-all-schemes.ipynb

1.25.1171.02.0 KB
Original Source

ITerm2 schemes for the Terminal

This is a little helper script to gather up all the color schemes in mbadolato/iTerm2-Color-Schemes, and put them in a single fragment extension for the Terminal.

C#
# Clone the repo into the temp directory

cd "$env:TEMP"
if (Test-Path -Path "$env:TEMP\iTerm2-Color-Schemes") {
    Remove-Item -Recurse -Force "$env:TEMP\iTerm2-Color-Schemes"
}
git clone --depth 1 https://github.com/mbadolato/iTerm2-Color-Schemes.git

cd "$env:TEMP\iTerm2-Color-Schemes"
C#
cd "$env:TEMP\iTerm2-Color-Schemes"

Write-Host "Importing schemes from '$env:TEMP\iTerm2-Color-Schemes'"

# Iterate over all the files in the `windowsterminal` directory

$allSchemesFiles = Get-ChildItem -Path "$env:TEMP\iTerm2-Color-Schemes\windowsterminal" -Filter *.json
Write-host "Found $($allSchemesFiles.Count) schemes"

$allSchemeJsons = @()

$allSchemesFiles | ForEach-Object {

    Write-Host "`r`e[K  Importing $_           " -NoNewline
    $json = Get-Content $_.FullName -Raw | ConvertFrom-Json
    $allSchemeJsons += $json

}
Write-Host ""
Write-Host "Imported json for $($allSchemeJsons.Count) schemes"

# Create a new fragment json in the temp directory with all the schemes added to a "schemes" array

$fragmentJson = @{
    "schemes" = $allSchemeJsons
} | ConvertTo-Json

# Remove the existing fragment json if it exists
$fragmentDir = $env:LOCALAPPDATA + "\Microsoft\Windows Terminal\Fragments\AllColorSchemes"
$fragmentPath = $fragmentDir + "\schemes.json"
if (Test-Path -Path $fragmentPath) {
    Remove-Item -Path $fragmentPath
}
# make sure the directory exists
New-Item -Path $fragmentDir -ItemType Directory -Force

# Write the fragment json to the fragments directory
Write-Output $fragmentJson | Out-File $fragmentPath -Encoding Utf8

write-host "Fragment json written to $fragmentPath"

After running this notebook, all the color schemes will be available in the Terminal. You'll probably need to go touch the settings to get them reloaded.