Created
August 24, 2018 13:10
-
-
Save steelbrain/f54007c3d6f3c5b260db38c01dfea284 to your computer and use it in GitHub Desktop.
iTerm2 Color Profile Printer
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
// Usage: node index.js | |
// Requires: npm install rgb-hex xml2json | |
// Requires color profile to be placed as Profile.itermcolors | |
// in same directory | |
const fs = require('fs') | |
const path = require('path') | |
const rgbHex = require('rgb-hex') | |
const { toJson } = require('xml2json') | |
const profilePath = path.join(__dirname, 'Profile.itermcolors') | |
if (!fs.existsSync(profilePath)) { | |
console.error(`Unable to find iTerm2 Profile at '${profilePath}'`) | |
process.exit(1) | |
} | |
const { plist } = toJson(fs.readFileSync(profilePath, 'utf8'), { | |
object: true, | |
}) | |
const IGNORE_COLOR_NAME = ['Color Space'] | |
function getColor(name, value, key){ | |
const foundIndex = value.key | |
.filter(item => !IGNORE_COLOR_NAME.includes(item)) | |
.findIndex(item => item.includes(key)) | |
if (foundIndex === -1) { | |
throw new Error(`Key '${key}' not found for entry '${name}'`) | |
} | |
return 0 | (255 * parseFloat(value.real[foundIndex])) | |
} | |
console.log('Colors:') | |
plist.dict.key.forEach(function(name, index) { | |
const value = plist.dict.dict[index] | |
const red = getColor(name, value, 'Red') | |
const green = getColor(name, value, 'Green') | |
const blue = getColor(name, value, 'Blue') | |
console.log(' ', name.padEnd(30), `rgb(${red},${green},${blue})`.padEnd(30), `hex(#${rgbHex(red, green, blue)})`) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment