Skip to content

Instantly share code, notes, and snippets.

@ny-a
Forked from atav32/convert_itermcolors.py
Last active September 11, 2021 11:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ny-a/35fe6c8e9babeff6a0fded6dfb58f563 to your computer and use it in GitHub Desktop.
Save ny-a/35fe6c8e9babeff6a0fded6dfb58f563 to your computer and use it in GitHub Desktop.
Convert .itermcolors file to Xresource hex
#!/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][3].text) * 255.0)
g = int(float(dicts[i][5].text) * 255.0)
b = int(float(dicts[i][7].text) * 255.0)
print("URxvt.color{}: ".format(i) + rgb_to_hex((r, g, b)) + " //" + keys[i].text)
if __name__ == '__main__':
main()
# sample is: https://github.com/jeffkreeftmeijer/appsignal.terminal/blob/master/appsignal-light.itermcolors
$> python convert_itermcolors.py appsignal-light.itermcolors
URxvt.color0: #463f31 //Ansi 0 Color
URxvt.color1: #3316c3 //Ansi 1 Color
URxvt.color2: #50af4c //Ansi 2 Color
URxvt.color3: #04aaef //Ansi 3 Color
URxvt.color4: #c46109 //Ansi 4 Color
URxvt.color5: #8f0c8a //Ansi 5 Color
URxvt.color6: #8a7d06 //Ansi 6 Color
URxvt.color7: #c5beb0 //Ansi 7 Color
URxvt.color8: #5f584a //Ansi 8 Color
URxvt.color9: #7255ff //Ansi 9 Color
URxvt.color10: #8fee8b //Ansi 10 Color
URxvt.color11: #43e9ff //Ansi 11 Color
URxvt.color12: #ffa048 //Ansi 12 Color
URxvt.color13: #ce4bc9 //Ansi 13 Color
URxvt.color14: #c9bc45 //Ansi 14 Color
URxvt.color15: #fffbf2 //Ansi 15 Color
URxvt.color16: #fffbf2 //Background Color
URxvt.color17: #463f31 //Bold Color
URxvt.color18: #463f31 //Foreground Color
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment