Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Convert .itermcolors file to html hex & rgb
#!/usr/bin/env python
#
# Convert .itermcolors files to hex colors for html
import sys
import xml.etree.ElementTree as ET
def rgb_to_hex(rgb):
return '#%02x%02x%02x' % rgb
# MAIN
def main():
if len(sys.argv) < 2:
print("usage: ./convert_itermcolors.py file.itermcolors")
exit()
tree = ET.parse(sys.argv[1])
root = tree.getroot()
keys = root.findall("./dict/key")
dicts = root.findall("./dict/dict")
for i in range(len(keys)):
r = int(float(dicts[i][1].text) * 255.0)
g = int(float(dicts[i][3].text) * 255.0)
b = int(float(dicts[i][5].text) * 255.0)
print(rgb_to_hex((r, g, b)) + " rgb({}, {}, {})".format(r, g, b) + " //" + keys[i].text)
if __name__ == '__main__':
main()
$> ./convert_itermcolors.py seoul256.itermcolors
#4e4e4e rgb(78, 78, 78) //Ansi 0 Color
#d68787 rgb(214, 135, 135) //Ansi 1 Color
#5f865f rgb(95, 134, 95) //Ansi 2 Color
#d8af5f rgb(216, 175, 95) //Ansi 3 Color
#85add4 rgb(133, 173, 212) //Ansi 4 Color
#d7afaf rgb(215, 175, 175) //Ansi 5 Color
#87afaf rgb(135, 175, 175) //Ansi 6 Color
#d0d0d0 rgb(208, 208, 208) //Ansi 7 Color
#626262 rgb(98, 98, 98) //Ansi 8 Color
#d75f87 rgb(215, 95, 135) //Ansi 9 Color
#87af87 rgb(135, 175, 135) //Ansi 10 Color
#ffd787 rgb(255, 215, 135) //Ansi 11 Color
#add4fb rgb(173, 212, 251) //Ansi 12 Color
#ffafaf rgb(255, 175, 175) //Ansi 13 Color
#87d7d7 rgb(135, 215, 215) //Ansi 14 Color
#e4e4e4 rgb(228, 228, 228) //Ansi 15 Color
#d0d0d0 rgb(208, 208, 208) //Foreground Color
#3a3a3a rgb(58, 58, 58) //Background Color
#e4e4e4 rgb(228, 228, 228) //Bold Color
#d0d0d0 rgb(208, 208, 208) //Cursor Color
#3a3a3a rgb(58, 58, 58) //Cursor Text Color
#d0d0d0 rgb(208, 208, 208) //Selected Text Color
#005f5f rgb(0, 95, 95) //Selection Color
@atav32

This comment has been minimized.

Copy link
Owner Author

atav32 commented Feb 26, 2018

@atav32

This comment has been minimized.

Copy link
Owner Author

atav32 commented Feb 26, 2018

Seoul256 iTerm theme: beautiful

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.