Skip to content

Instantly share code, notes, and snippets.

@dcdunkan
Last active May 5, 2025 23:56
Show Gist options
  • Save dcdunkan/b7f1be2d2b7095327783c6d94043d09e to your computer and use it in GitHub Desktop.
Save dcdunkan/b7f1be2d2b7095327783c6d94043d09e to your computer and use it in GitHub Desktop.
Script for converting VSCode theme to Kitty terminal theme
/**
* Script for converting VSCode theme to Kitty terminal theme.
*
* ```sh
* deno code-to-kitty-theme.ts <url or file>
* ```
* and the output will be written to `current-theme.conf` file in the working directory.
*
* Arugment can either be a remote URL to a theme JSON file or a local relative / absolute path.
*/
import { resolve, toFileUrl } from "jsr:@std/path";
if (Deno.args.length != 1) {
throw new Error("Invalid arguments.");
}
const argument = Deno.args[0];
const url = URL.canParse(argument) ? argument : toFileUrl(resolve(argument));
const response = await fetch(url);
const { colors: themeColors } = await response.json();
const KEY_MAP: {
[key: string]: [jsonKey: string, removeAlpha?: boolean];
} = {
"background": ["terminal.background"],
"foreground": ["terminal.foreground"],
"cursor": ["terminalCursor.foreground"],
"cursor_text_color": ["terminalCursor.background", true],
"selection_foreground": ["terminal.background", true],
"selection_background": ["terminal.selectionBackground", true],
"color0": ["terminal.ansiBlack"],
"color8": ["terminal.ansiBrightBlack"],
"color1": ["terminal.ansiRed"],
"color9": ["terminal.ansiBrightRed"],
"color2": ["terminal.ansiGreen"],
"color10": ["terminal.ansiBrightGreen"],
"color3": ["terminal.ansiYellow"],
"color11": ["terminal.ansiBrightYellow"],
"color4": ["terminal.ansiBlue"],
"color12": ["terminal.ansiBrightBlue"],
"color5": ["terminal.ansiMagenta"],
"color13": ["terminal.ansiBrightMagenta"],
"color6": ["terminal.ansiCyan"],
"color14": ["terminal.ansiBrightCyan"],
"color7": ["terminal.ansiWhite"],
"color15": ["terminal.ansiBrightWhite"],
};
function removeAlpha(hex: string): string {
const hash = hex.indexOf("#");
if (hash == -1) return "#" + hex.slice(0, 6);
else if (hash == 0) return hex.slice(0, 7);
throw new Error("invalid hex string input: " + hex);
}
const lines: string[] = [];
for (const key in KEY_MAP) {
const [themeKey, alpha = false] = KEY_MAP[key];
if (themeKey in themeColors) {
const color = alpha
? removeAlpha(themeColors[themeKey])
: themeColors[themeKey];
lines.push(`${key.padEnd(24, " ")}${color}`);
}
}
await Deno.writeTextFile("current-theme.conf", lines.join("\n") + "\n");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment