Skip to content

Instantly share code, notes, and snippets.

@2xAA
Last active September 23, 2024 20:51
Show Gist options
  • Save 2xAA/bd01638dc9ca46c590fda06c4ef0cc5a to your computer and use it in GitHub Desktop.
Save 2xAA/bd01638dc9ca46c590fda06c4ef0cc5a to your computer and use it in GitHub Desktop.
Convert iTerm2 "itermcolors" file to VSCode terminal color scheme
/* Generate colors using: `plutil -convert json` in your terminal */
const col = [] // run your .itermcolors file through the above parser and replace the array with the output
function componentToHex(c) {
const hex = c.toString(16)
return hex.length === 1 ? `0${hex}` : hex
}
const mapping = {
'terminal.background':'Background Color',
'terminal.foreground':'Foreground Color',
'terminalCursor.background':'Cursor Text Color',
'terminalCursor.foreground':'Cursor Color',
'terminal.ansiBlack':'Ansi 0 Color',
'terminal.ansiBlue':'Ansi 4 Color',
'terminal.ansiBrightBlack':'Ansi 8 Color',
'terminal.ansiBrightBlue':'Ansi 12 Color',
'terminal.ansiBrightCyan':'Ansi 14 Color',
'terminal.ansiBrightGreen':'Ansi 10 Color',
'terminal.ansiBrightMagenta':'Ansi 13 Color',
'terminal.ansiBrightRed':'Ansi 9 Color',
'terminal.ansiBrightWhite':'Ansi 15 Color',
'terminal.ansiBrightYellow':'Ansi 11 Color',
'terminal.ansiCyan':'Ansi 6 Color',
'terminal.ansiGreen':'Ansi 2 Color',
'terminal.ansiMagenta':'Ansi 5 Color',
'terminal.ansiRed':'Ansi 1 Color',
'terminal.ansiWhite':'Ansi 7 Color',
'terminal.ansiYellow':'Ansi 3 Color'
}
console.log(JSON.stringify(Object.keys(mapping).reduce((obj, vsCodeKey) => {
const itermKey = mapping[vsCodeKey]
const red = componentToHex(Math.round(col[0][itermKey]['Red Component'] * 255))
const green = componentToHex(Math.round(col[0][itermKey]['Green Component'] * 255))
const blue = componentToHex(Math.round(col[0][itermKey]['Blue Component'] * 255))
obj[vsCodeKey] = `#${red}${green}${blue}`
return obj
}, {}), null, 2))
@experimatt
Copy link

Thanks for sharing this, Sam! I just adapted this script to take a json file as an argument and threw it up in a gist here: https://gist.github.com/experimatt/71c8145d72acc034123fcfba0213c317

@2xAA
Copy link
Author

2xAA commented Apr 12, 2020

@experimatt No problem, glad it was useful 😁

@t1-10
Copy link

t1-10 commented Aug 5, 2021

I'm on iTerm2 Build 3.4.8. I didn't fine the .itermcolors file. But I was able to generate vscode config with these steps:

  1. In iTerm preferences on the Profiles section on Colors tab on the bottom left corner press Other Actions -> Save Profile as JSON.
  2. Copy the content of the generated JSON file to this gist's con constant like this: con = [<the json file content>]
  3. Run the rest of the gist.

@ian-h-chamberlain
Copy link

Btw, for anyone else who comes across this — You can also convert the .itermcolors (which is plist XML format) to JSON with plutil -convert json if you don't want to install another random NPM package.

Thanks for this handy little script!

@2xAA
Copy link
Author

2xAA commented Jun 25, 2024

@ian-h-chamberlain Ah that's really handy, thanks for that!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment