-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathterm-to-gui.rb
42 lines (33 loc) · 951 Bytes
/
term-to-gui.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
#!/usr/bin/env ruby
require 'yaml'
require 'stringio'
def die msg
STDERR.puts msg
exit 1
end
pal = ARGV[0]
die "Please specify a palette on the command line." if !pal || pal == ''
fname = "#{File.dirname(__FILE__)}/palettes/#{pal}.yaml"
die "Palette #{pal} doesn't exist." unless File.exist? fname
colors = YAML.load_file(fname)['colors']
while STDIN.gets do
if ~/^let g:colors_name\s*=\s*/
puts "#{$&}'#{pal}'"
elsif ~/^(hi(ghlight){0,1}\s+[A-Z][A-Za-z0-9]+\s+).*cterm[bf]g=/
pre = $1
# Get values
hi = Hash[$_.chomp.scan(/([a-z]+)=([^ ]+)/)]
ctermbg = hi['ctermbg'] && hi['ctermbg'].to_i
if ctermbg && ctermbg > 0 && colors[ctermbg]
hi['guibg'] = "##{colors[ctermbg]}"
end
ctermfg = hi['ctermfg'] && hi['ctermfg'].to_i
if ctermfg && colors[ctermfg]
hi['guifg'] = "##{colors[ctermfg]}"
end
print pre
puts hi.map { |k,v| "#{k}=#{v}" }.join(' ')
else
puts $_
end
end