Created
July 3, 2025 15:51
-
-
Save davioliveira-dev/4637ad6d0842a36beea185fadcedee92 to your computer and use it in GitHub Desktop.
Script to convert Vscode theme to Ghostty terminal theme
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bun | |
import fs from "fs"; | |
import { parse } from "jsonc-parser"; | |
// Usage | |
// bun convert.ts <file>.jsonc <themne-name>.conf | |
// You get your jsonc file from Developer: Generate Color Theme from Current Settings on Vscode command pallete | |
if (process.argv.length < 3) { | |
console.error("Usage: convert.ts <vscode-theme.jsonc> [output.ghostty]"); | |
process.exit(1); | |
} | |
const inFile = process.argv[2]; | |
const outFile = process.argv[3] || inFile.replace(/\.(jsonc|json)$/, ".ghostty"); | |
const text = fs.readFileSync(inFile, "utf-8"); | |
const errors: any[] = []; | |
const theme = parse(text, errors, { allowTrailingComma: true, disallowComments: false }); | |
if (errors.length > 0) { | |
console.error("JSONC parse errors:", errors); | |
process.exit(1); | |
} | |
// map 16 ANSI colors from `colors` object | |
const ansiNames = [ | |
"Black","Red","Green","Yellow","Blue","Magenta","Cyan","White", | |
"BrightBlack","BrightRed","BrightGreen","BrightYellow","BrightBlue","BrightMagenta","BrightCyan","BrightWhite" | |
]; | |
const ansiPalette = ansiNames.map(name => | |
theme.colors?.[`terminal.ansi${name}`] ?? "#000000" | |
); | |
const bg = theme.colors?.["editor.background"] ?? "#000000"; | |
const fg = theme.colors?.["editor.foreground"] ?? "#ffffff"; | |
const cursor = theme.colors?.["editorCursor.foreground"] ?? fg; | |
const selBg = theme.colors?.["editor.selectionBackground"] ?? bg; | |
const selFg = fg; | |
const lines = ansiPalette.map((c, i) => `palette = ${i}=${c}`); | |
lines.push(`background = ${bg}`, `foreground = ${fg}`, `cursor-color = ${cursor}`); | |
lines.push(`cursor-text = ${fg}`, `selection-background = ${selBg}`, `selection-foreground = ${selFg}`); | |
fs.writeFileSync(outFile, lines.join("\n") + "\n"); | |
console.log("Written to", outFile); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment