Skip to content

Instantly share code, notes, and snippets.

@jaspervdj
Created October 26, 2011 12:05
Show Gist options
  • Save jaspervdj/1316153 to your computer and use it in GitHub Desktop.
Save jaspervdj/1316153 to your computer and use it in GitHub Desktop.
Generate Solarized theme for urxvt
# Map color names to actual values
SOLARIZED = {
:base03 => '#002b36', # brblack
:base02 => '#073642', # black
:base01 => '#586e75', # brgreen
:base00 => '#657b83', # bryellow
:base0 => '#839496', # brblue
:base1 => '#93a1a1', # brcyan
:base2 => '#eee8d5', # white
:base3 => '#fdf6e3', # brwhite
:yellow => '#b58900', # yellow
:orange => '#cb4b16', # brred
:red => '#dc322f', # red
:magenta => '#d33682', # magenta
:violet => '#6c71c4', # brmagenta
:blue => '#268bd2', # blue
:cyan => '#2aa198', # cyan
:green => '#859900' # green
}
# Base terminal color mapping
BASE = {
'color0' => :base02,
'color8' => :base03,
'color1' => :red,
'color9' => :orange,
'color2' => :green,
'color10' => :base01,
'color3' => :yellow,
'color11' => :base00,
'color4' => :blue,
'color12' => :orange,
'color5' => :magenta,
'color13' => :violet,
'color6' => :cyan,
'color14' => :base1,
'color7' => :base2,
'color15' => :base3
}
HEADER = '# Solarized theme'
def make_theme(colors)
hash = Hash.new { |h, k| h[k] = BASE[k] }
colors.each { |k, v| hash[k] = v }
return hash
end
def write_theme(file, theme)
file.puts HEADER
file.puts "*fading: 40"
file.puts "*fadeColor: #{SOLARIZED[theme['background']]}"
file.puts "*foreground: #{SOLARIZED[theme['foreground']]}"
file.puts "*background: #{SOLARIZED[theme['background']]}"
(0 .. 15).each do |i|
file.puts "*color#{i}: #{SOLARIZED[theme["color#{i}"]]}"
end
end
DARK = make_theme({
'foreground' => :base0,
'background' => :base03
})
BRIGHT = make_theme({
'foreground' => :base01,
'background' => :base3
})
if ARGV.size < 1 then
puts "Usage: #{$0} <dark|bright>"
exit 1
end
theme = nil
case ARGV.first
when 'dark'
theme = DARK
when 'bright'
theme = BRIGHT
else
puts "Unknown theme"
exit 1
end
xdefaults = File.expand_path('~/.Xdefaults')
lines = []
lines = File.readlines xdefaults
lines = lines.take_while do |l|
l.strip != HEADER
end
File.open(xdefaults, 'w') do |f|
lines.each { |l| f.puts l }
write_theme(f, theme)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment