Created
January 14, 2013 04:57
-
-
Save dangra/4527855 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
"""Solarized theme for gnome-terminal | |
see http://ethanschoonover.com/solarized | |
""" | |
import posixpath | |
from optparse import OptionParser | |
import gconf | |
BASE03 = '#002B36' | |
BASE02 = '#073642' | |
BASE01 = '#586E75' | |
BASE00 = '#657B83' | |
BASE0 = '#839496' | |
BASE1 = '#93A1A1' | |
BASE2 = '#EEE8D5' | |
BASE3 = '#FDF6E3' | |
YELLOW = '#B58900' | |
ORANGE = '#CB4B16' | |
RED = '#DC322F' | |
MAGENTA = '#D33682' | |
VIOLET = '#6C71C4' | |
BLUE = '#268BD2' | |
CYAN = '#2AA198' | |
GREEN = '#859900' | |
# 16 colors palette | |
PALETTE = [BASE02, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, BASE2, | |
BASE03, ORANGE, BASE01, BASE00, BASE0, VIOLET, BASE1, BASE3] | |
# scheme = (background, foreground, bold) | |
DARK = (BASE03, BASE0, BASE1) | |
LIGHT = (BASE3, BASE00, BASE01) | |
def _set_profile(profile, palette, background, foreground, bold, **extras): | |
c = gconf.client_get_default() | |
pp = lambda k: _gpath('profiles', profile, k) | |
# Solarized specifics | |
c.set_string(pp('visible_name'), profile) | |
c.set_string(pp('palette'), ':'.join(palette)) | |
c.set_string(pp('bold_color'), bold) | |
c.set_string(pp('background_color'), background) | |
c.set_string(pp('foreground_color'), foreground) | |
c.set_bool(pp('use_theme_colors'), False) | |
c.set_bool(pp('use_theme_background'), False) | |
c.set_bool(pp('bold_color_same_as_fg'), False) | |
# profile extras | |
for k, v in extras.iteritems(): | |
_set_value(c, pp(k), v) | |
# Add name to profile list | |
profiles = c.get_list(_gpath('global/profile_list'), gconf.VALUE_STRING) | |
if profile not in profiles: | |
profiles.append(profile) | |
c.set_list(_gpath('global/profile_list'), gconf.VALUE_STRING, profiles) | |
# Set profile as default for new windows | |
c.set_string(_gpath('global/default_profile'), profile) | |
def _solarize(profile='Solarized', scheme='dark'): | |
extras = { | |
'solarized_scheme': scheme, # used to support scheme toggling | |
'default_show_menubar': False, | |
'use_system_font': False, | |
'font': 'Inconsolata Medium 10', | |
} | |
bg, fg, bd = DARK if scheme == 'dark' else LIGHT | |
_set_profile(profile, PALETTE, bg, fg, bd, **extras) | |
def _next_scheme(profile): | |
c = gconf.client_get_default() | |
scheme = c.get_string(_gpath('profiles', profile, 'solarized_scheme')) | |
return 'light' if scheme == 'dark' else 'dark' | |
def _gpath(*parts): | |
return posixpath.join('/apps/gnome-terminal', *parts) | |
def _set_value(c, k, v): | |
if isinstance(v, str): | |
c.set_string(k, v) | |
elif isinstance(v, bool): | |
c.set_bool(k, v) | |
elif isinstance(v, int): | |
c.set_int(k, v) | |
else: | |
raise ValueError('Unknown type for key %s: %s', k, type(v)) | |
def main(): | |
op = OptionParser() | |
op.add_option('-n', '--profile', default='Solarized', | |
help='gnome-terminal profile name to set, default="%default"') | |
opts, args = op.parse_args() | |
cmd = args[0] if args else _next_scheme(opts.profile) | |
if cmd in ('dark', 'light'): | |
_solarize(profile=opts.profile, scheme=cmd) | |
else: | |
op.error('Unknown command: %s' % cmd) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment