Skip to content

Instantly share code, notes, and snippets.

@ayechan
Created April 6, 2013 23:47
Show Gist options
  • Save ayechan/5328145 to your computer and use it in GitHub Desktop.
Save ayechan/5328145 to your computer and use it in GitHub Desktop.
A command-line tool converting .itermcolors (color schemes of iTerm2) to Console2 (for Windows) settings xml entries.
require 'plist'
def conv_color_component(fval)
( 255.0 * fval ) .to_i
end
def conv_color(node)
r = conv_color_component(node['Red Component'])
g = conv_color_component(node['Green Component'])
b = conv_color_component(node['Blue Component'])
"r=\"#{r}\" g=\"#{g}\" b=\"#{b}\""
end
COLOUR_MAP = {
'Background Color' => [0],
'Ansi 1 Color' => [4],
'Ansi 2 Color' => [8],
'Ansi 3 Color' => [12],
'Ansi 4 Color' => [1],
'Ansi 5 Color' => [5],
'Ansi 6 Color' => [9],
'Ansi 7 Color' => [13],
'Ansi 8 Color' => [2],
'Ansi 9 Color' => [6],
'Ansi 10 Color' => [10],
'Ansi 11 Color' => [14],
'Ansi 12 Color' => [3],
'Ansi 13 Color' => [7],
'Ansi 14 Color' => [11],
'Ansi 15 Color' => [15],
}
result={}
Plist::parse_xml(ARGF).each do |key, value|
if COLOUR_MAP.key?(key)
COLOUR_MAP[key].each do |number|
result[number] = conv_color(value)
end
end
end
result.sort.each { |k,v| puts "<color id=\"#{k}\" #{v}/>" }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment