Skip to content

Instantly share code, notes, and snippets.

@j9ac9k
Last active April 18, 2019 14:52
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save j9ac9k/d0f626e1d299fedd9b8d29e47b90cb57 to your computer and use it in GitHub Desktop.
Save j9ac9k/d0f626e1d299fedd9b8d29e47b90cb57 to your computer and use it in GitHub Desktop.
Python Script to Convert ITerm XML color config files to Putty color registry files
import xml.etree.ElementTree as ET
import sys
try:
input_file = sys.argv[1]
tree = ET.parse(input_file)
except:
raise 'Provide xml filename to convert'
root = tree.getroot()
mapping = {}
mapping["Foreground Color"]= "Colour0"
mapping["Background Color"]= "Colour2"
mapping["Cursor Text Color"]= "Colour4"
mapping["Cursor Color"]= "Colour5"
mapping["Selected Text Color"]= "Colour1"
mapping["Selection Color"]= "Colour3"
mapping["Ansi 0 Color"]= "Colour6"
mapping["Ansi 1 Color"]= "Colour8"
mapping["Ansi 2 Color"]= "Colour10"
mapping["Ansi 3 Color"]= "Colour12"
mapping["Ansi 4 Color"]= "Colour14"
mapping["Ansi 5 Color"]= "Colour16"
mapping["Ansi 6 Color"]= "Colour18"
mapping["Ansi 7 Color"]= "Colour20"
mapping["Ansi 8 Color"]= "Colour7"
mapping["Ansi 9 Color"]= "Colour9"
mapping["Ansi 10 Color"]= "Colour11"
mapping["Ansi 11 Color"]= "Colour13"
mapping["Ansi 12 Color"]= "Colour15"
mapping["Ansi 13 Color"]= "Colour17"
mapping["Ansi 14 Color"]= "Colour19"
mapping["Ansi 15 Color"]= "Colour21"
output = []
for child in root[0]:
if child.text == 'Bold Color':
continue
elif not child.text.startswith('\n'):
color = child.text
continue
color_list = [str(int(float(color.text) * 255)) for color in child.findall('real')[::-1]]
output.append('"{}"="{}"'.format(mapping[color], ','.join(color_list)))
theme = input_file[:-4]
heading = ['Windows Registry Editor Version 5.00 ',
'',
'[HKEY_CURRENT_USER\Software\SimonTatham\PuTTY\Sessions\{}]'.format(theme)]
with open(input_file.replace('xml', 'reg'), 'wt+') as f:
f.write('\n'.join(heading))
f.write('\n')
f.write('\n'.join(output))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment