-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathconvertor.rb
63 lines (52 loc) · 1.82 KB
/
convertor.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# https://github.com/caseyhoward/nokogiri-plist
require 'nokogiri-plist'
# /apps/gnome-terminal/profiles/Default
# -> background_color
# -> bold_color
# -> foreground_color
# -> palette
def convert_to_key(real_color)
return "%02X" % (real_color * 255)
end
def gconf2_command(gconf_key, gconf_type, gconf_value)
return "gconftool-2 --set /apps/gnome-terminal/profiles/Default/#{gconf_key} --type #{gconf_type} \"#{gconf_value}\""
end
def get_rgb(doc_hash)
red = convert_to_key(doc_hash["Red Component"])
green = convert_to_key(doc_hash["Green Component"])
blue = convert_to_key(doc_hash["Blue Component"])
return "##{red}#{green}#{blue}"
end
ARGV.each do |iterm_theme|
f = open(iterm_theme)
doc = Nokogiri::PList(f)
keys_to_export = Hash.new
keys_to_export["palette"] = Array.new(16)
doc.keys.each do |doc_key|
if doc_key =~ /Ansi \d+ Color/
slot = doc_key.scan(/Ansi (\d+) Color/)[0][0].to_i
hex = get_rgb(doc[doc_key])
keys_to_export["palette"][slot] = hex
end
if doc_key =~ /Background Color/
# This goes directly to background_color
hex = get_rgb(doc[doc_key])
keys_to_export["background_color"] = hex
end
if doc_key =~ /Foreground Color/
# This goes directly to foreground_color
hex = get_rgb(doc[doc_key])
keys_to_export["foreground_color"] = hex
end
if doc_key =~ /Bold Color/
# This goes directly to bold color
hex = get_rgb(doc[doc_key])
keys_to_export["bold_color"] = hex
end
end
puts "# " + iterm_theme
puts gconf2_command("foreground_color", "string", keys_to_export["foreground_color"])
puts gconf2_command("background_color", "string", keys_to_export["background_color"])
puts gconf2_command("bold_color", "string", keys_to_export["bold_color"])
puts gconf2_command("palette", "string", keys_to_export["palette"].join(':'))
end