Skip to content

Instantly share code, notes, and snippets.

@scintill
Created October 13, 2013 01:27
Show Gist options
  • Save scintill/6956980 to your computer and use it in GitHub Desktop.
Save scintill/6956980 to your computer and use it in GitHub Desktop.
convert powerline colorscheme to airline
" This attempts to replicate Powerline with the solarized256 colorscheme and the default theme.
" It was generated from the Powerline colorscheme struct and a script attempting to match powerline
" items to the Airline layout.
<?php
// TODO filename bold - accent?
$json = file_get_contents('solarized256.vimv');
$json = str_replace("'", '"', $json);
$powerlinedata = json_decode($json, true);
$palette = array();
foreach ($powerlinedata as $segment => $colors) {
switch ($segment) {
case 'mode_indicator':
$segment = 'airline_a';
break;
case 'branch':
$segment = 'airline_b';
break;
case 'fileinfo.filepath':
case 'filepath':
$segment = 'airline_c';
break;
case 'filetype':
$segment = 'airline_x';
break;
case 'fileencoding':
$segment = 'airline_y';
break;
case 'lineinfo':
$segment = 'airline_z';
break;
case 'SPLIT':
$segment = 'airline_gap';
break;
case 'static_str':
$segment = 'specbuf';
break;
case 'ctrlp:item':
case 'ctrlp:prev':
case 'ctrlp:focus':
break;
default:
fprintf(STDERR, "unknown segment %s\n", $segment);
$segment = null;
}
if ($segment === null) {
continue;
}
foreach ($colors as $mode => $colors) {
switch ($mode) {
case 'n':
$mode = 'normal';
break;
case 'N':
$mode = 'inactive';
break;
case 'i':
$mode = 'insert';
break;
case 'r':
$mode = 'replace';
break;
case 'v':
$mode = 'visual';
break;
default:
fprintf(STDERR, 'unknown mode '.$mode."\n");
$mode = null;
break;
}
if ($mode == null) {
continue;
}
$p = array(hex($colors['guifg']), hex($colors['guibg']), $colors['ctermfg'], $colors['ctermbg'], $colors['attr']);
if ($segment == 'specbuf' && $mode == 'normal') {
$palette['specbuf']['airline_a'] = $p;
} else if (strpos($segment, "ctrlp:") === 0) {
if ($segment == 'ctrlp:item') {
$palette['ctrlp']['CtrlPwhite'] = $p;
} else if ($segment == 'ctrlp:prev') {
$palette['ctrlp']['CtrlPlight'] = $p;
} else if ($segment == 'ctrlp:focus') {
$palette['ctrlp']['CtrlPdark'] = $p;
}
} else {
$palette[$mode][$segment] = $p;
}
}
}
function hex($i) {
return '#'.str_pad(dechex($i), 6, '0', STR_PAD_LEFT);
}
$vim = json_encode($palette);
$vim = str_replace('"', "'", $vim);
echo 'let g:airline#themes#powerline_solarized256#palette = ',prettyPrint($vim),"\n";
// powerline hides modeindicator on inactive. airline shows "Help" as section a even on inactive, so we need to style it
$palette['inactive']['airline_a'] = 'inactive.airline_b';
$modes = array('normal', 'inactive', 'insert', 'replace', 'visual');
$segments = array('a','b','c','x','y','z');
foreach ($modes as $mode) {
foreach ($segments as $segment) {
$segment = 'airline_'.$segment;
if (!isset($palette[$mode][$segment])) {
fprintf(STDERR, 'mode '.$mode.' segment '.$segment." not set\n");
echo "let g:airline#themes#powerline_solarized256#palette.$mode.$segment = g:airline#themes#powerline_solarized256#palette.normal.$segment\n";
} else if (is_string($palette[$mode][$segment])) {
echo "let g:airline#themes#powerline_solarized256#palette.$mode.$segment = g:airline#themes#powerline_solarized256#palette.",$palette[$mode][$segment],"\n";
}
}
}
$ctrlp = array('CtrlPdark', 'CtrlPlight', 'CtrlPwhite', 'CtrlParrow1', 'CtrlParrow2', 'CtrlParrow3');
foreach ($ctrlp as $ctrlp) {
if (!isset($palette['ctrlp'][$ctrlp])) {
fprintf(STDERR, 'ctrlp '.$ctrlp.' not set'."\n");
}
}
function prettyPrint($json) {
$json = str_replace("\n", '', $json);
//return $json;
$result = '';
$pos = 0;
$strLen = strlen($json);
$indentStr = ' ';
$newLine = "\n\\ ";
$prevChar = '';
$outOfQuotes = true;
for ($i = 0; $i <= $strLen; $i++) {
// Grab the next character in the string.
$char = substr($json, $i, 1);
// Are we inside a quoted string?
if ($char == '"' && $prevChar != '\\') {
$outOfQuotes = !$outOfQuotes;
// If this character is the end of an element,
// output a new line and indent the next line.
} else if (($char == '}' || $char == ']') && $outOfQuotes) {
$result .= $newLine;
$pos--;
for ($j = 0; $j < $pos; $j++) {
$result .= $indentStr;
}
}
// Add the character to the result string.
$result .= $char;
// If the last character was the beginning of an element,
// output a new line and indent the next line.
if (($char == ',' || $char == '{' || $char == '[') && $outOfQuotes) {
$result .= $newLine;
if ($char == '{' || $char == '[') {
$pos++;
}
for ($j = 0; $j < $pos; $j++) {
$result .= $indentStr;
}
}
$prevChar = $char;
}
return $result;
}
?>
" airline-specific theming
let g:airline#themes#powerline_solarized256#palette.normal.airline_warning = g:airline#themes#powerline_solarized256#palette.normal.airline_c "['#5f5f00', '#ff5f00', 247, 52]
let g:airline#themes#powerline_solarized256#palette.normal_modified = {'airline_warning': g:airline#themes#powerline_solarized256#palette.normal.airline_warning}
let g:airline#themes#powerline_solarized256#palette.insert.airline_warning = g:airline#themes#powerline_solarized256#palette.normal.airline_warning
let g:airline#themes#powerline_solarized256#palette.insert_modified = {'airline_warning': g:airline#themes#powerline_solarized256#palette.normal.airline_warning}
let g:airline#themes#powerline_solarized256#palette.replace.airline_warning = g:airline#themes#powerline_solarized256#palette.normal.airline_warning
let g:airline#themes#powerline_solarized256#palette.replace_modified = {'airline_warning': g:airline#themes#powerline_solarized256#palette.normal.airline_warning}
let g:airline#themes#powerline_solarized256#palette.visual.airline_warning = g:airline#themes#powerline_solarized256#palette.normal.airline_warning
let g:airline#themes#powerline_solarized256#palette.visual_modified = {'airline_warning': g:airline#themes#powerline_solarized256#palette.normal.airline_warning}
{'ctrlp:item': {'n': {'ctermbg': 24, 'attr': 'bold', 'ctermfg': 254, 'guibg': 24455, 'guifg': 15657173}}, 'errors': {'n': {'ctermbg': 235, 'attr': 'bold', 'ctermfg': 166, 'guibg': 472642, 'guifg': 13323030}, 'N': {'ctermbg': 234, 'attr': 'bold', 'ctermfg': 241, 'guibg': 11062, 'guifg': 6447714}}, 'status': {'n': {'ctermbg': 235, 'attr': 'NONE', 'ctermfg': 64, 'guibg': 472642, 'guifg': 8755456}, 'N': {'ctermbg': 235, 'attr': 'NONE', 'ctermfg': 241, 'guibg': 472642, 'guifg': 6447714}}, 'mode_indicator': {'r': {'ctermbg': 61, 'attr': 'bold', 'ctermfg': 231, 'guibg': 7107012, 'guifg': 16777215}, 's': {'ctermbg': 241, 'attr': 'bold', 'ctermfg': 231, 'guibg': 6447714, 'guifg': 16777215}, 'v': {'ctermbg': 208, 'attr': 'bold', 'ctermfg': 160, 'guibg': 16746240, 'guifg': 14430767}, 'i': {'ctermbg': 231, 'attr': 'bold', 'ctermfg': 23, 'guibg': 16777215, 'guifg': 24415}, 'n': {'ctermbg': 148, 'attr': 'bold', 'ctermfg': 22, 'guibg': 11523840, 'guifg': 24320}}, 'rvm:statusline': {'i': {'ctermbg': 235, 'attr': 'NONE', 'ctermfg': 117, 'guibg': 472642, 'guifg': 8902655}, 'n': {'ctermbg': 236, 'attr': 'NONE', 'ctermfg': 241, 'guibg': 3158064, 'guifg': 6447714}}, 'fileinfo.flags': {'n': {'ctermbg': '', 'attr': 'bold', 'ctermfg': 234, 'guibg': '', 'guifg': 11062}, 'i': {'ctermbg': '', 'attr': 'bold', 'ctermfg': 234, 'guibg': '', 'guifg': 11062}, 'N': {'ctermbg': '', 'attr': 'NONE', 'ctermfg': 241, 'guibg': '', 'guifg': 6447714}}, 'pwd': {'i': {'ctermbg': 235, 'attr': 'NONE', 'ctermfg': 117, 'guibg': 472642, 'guifg': 8902655}, 'n': {'ctermbg': 236, 'attr': 'NONE', 'ctermfg': 241, 'guibg': 3158064, 'guifg': 6447714}}, 'lustyexplorer:SPLIT': {'n': {'ctermbg': 235, 'attr': 'NONE', 'ctermfg': 239, 'guibg': 472642, 'guifg': 5131854}, 'N': {'ctermbg': 235, 'attr': 'NONE', 'ctermfg': 239, 'guibg': 472642, 'guifg': 5131854}}, 'nerdtree:SPLIT': {'n': {'ctermbg': 235, 'attr': 'NONE', 'ctermfg': 239, 'guibg': 472642, 'guifg': 5131854}, 'N': {'ctermbg': 235, 'attr': 'NONE', 'ctermfg': 239, 'guibg': 472642, 'guifg': 5131854}}, 'branch': {'n': {'ctermbg': 33, 'attr': 'NONE', 'ctermfg': 234, 'guibg': 2526162, 'guifg': 11062}, 'N': {'ctermbg': 234, 'attr': 'NONE', 'ctermfg': 241, 'guibg': 11062, 'guifg': 6447714}}, 'raw': {'n': {'ctermbg': 33, 'attr': 'NONE', 'ctermfg': 234, 'guibg': 2526162, 'guifg': 11062}, 'N': {'ctermbg': 234, 'attr': 'NONE', 'ctermfg': 241, 'guibg': 11062, 'guifg': 6447714}}, 'gundo:SPLIT': {'n': {'ctermbg': 235, 'attr': 'NONE', 'ctermfg': 231, 'guibg': 472642, 'guifg': 16777215}, 'N': {'ctermbg': 235, 'attr': 'NONE', 'ctermfg': 231, 'guibg': 472642, 'guifg': 16777215}}, 'fileinfo.filepath': {'n': {'ctermbg': '', 'attr': 'NONE', 'ctermfg': 252, 'guibg': '', 'guifg': 13684944}, 'i': {'ctermbg': '', 'attr': 'NONE', 'ctermfg': 117, 'guibg': '', 'guifg': 8902655}, 'N': {'ctermbg': '', 'attr': 'NONE', 'ctermfg': 241, 'guibg': '', 'guifg': 6447714}}, 'tagbar:static_str.name': {'n': {'ctermbg': 24, 'attr': 'bold', 'ctermfg': 252, 'guibg': 24455, 'guifg': 13684944}, 'N': {'ctermbg': 235, 'attr': 'bold', 'ctermfg': 239, 'guibg': 472642, 'guifg': 5131854}}, 'ctrlp:count': {'n': {'ctermbg': 234, 'attr': 'NONE', 'ctermfg': 244, 'guibg': 11062, 'guifg': 8623254}}, 'lustyexplorer:static_str.buffer': {'n': {'ctermbg': 33, 'attr': 'NONE', 'ctermfg': 230, 'guibg': 2526162, 'guifg': 16643811}, 'N': {'ctermbg': 235, 'attr': 'NONE', 'ctermfg': 241, 'guibg': 472642, 'guifg': 6447714}}, 'command_t:raw.line': {'n': {'ctermbg': 235, 'attr': 'NONE', 'ctermfg': 231, 'guibg': 472642, 'guifg': 16777215}, 'N': {'ctermbg': 235, 'attr': 'NONE', 'ctermfg': 241, 'guibg': 472642, 'guifg': 6447714}}, 'gundo:static_str.name': {'n': {'ctermbg': 31, 'attr': 'bold', 'ctermfg': 230, 'guibg': 34735, 'guifg': 16643811}, 'N': {'ctermbg': 234, 'attr': 'bold', 'ctermfg': 245, 'guibg': 11062, 'guifg': 9675169}}, 'ctrlp:pwd': {'n': {'ctermbg': 235, 'attr': 'NONE', 'ctermfg': 64, 'guibg': 472642, 'guifg': 8755456}}, 'fileencoding': {'i': {'ctermbg': 235, 'attr': 'NONE', 'ctermfg': 117, 'guibg': 472642, 'guifg': 8902655}, 'n': {'ctermbg': 236, 'attr': 'NONE', 'ctermfg': 241, 'guibg': 3158064, 'guifg': 6447714}}, 'minibufexplorer:SPLIT': {'n': {'ctermbg': 235, 'attr': 'NONE', 'ctermfg': 239, 'guibg': 472642, 'guifg': 5131854}, 'N': {'ctermbg': 235, 'attr': 'NONE', 'ctermfg': 239, 'guibg': 472642, 'guifg': 5131854}}, 'command_t:SPLIT': {'n': {'ctermbg': 235, 'attr': 'NONE', 'ctermfg': 231, 'guibg': 472642, 'guifg': 16777215}, 'N': {'ctermbg': 235, 'attr': 'NONE', 'ctermfg': 231, 'guibg': 472642, 'guifg': 16777215}}, 'ctrlp:SPLIT': {'n': {'ctermbg': 234, 'attr': 'NONE', 'ctermfg': 231, 'guibg': 11062, 'guifg': 16777215}}, 'rvm:string': {'i': {'ctermbg': 235, 'attr': 'NONE', 'ctermfg': 117, 'guibg': 472642, 'guifg': 8902655}, 'n': {'ctermbg': 236, 'attr': 'NONE', 'ctermfg': 241, 'guibg': 3158064, 'guifg': 6447714}}, 'filesize': {'n': {'ctermbg': 33, 'attr': 'NONE', 'ctermfg': 234, 'guibg': 2526162, 'guifg': 11062}, 'N': {'ctermbg': 234, 'attr': 'NONE', 'ctermfg': 241, 'guibg': 11062, 'guifg': 6447714}}, 'ctrlp:prev': {'n': {'ctermbg': 235, 'attr': 'NONE', 'ctermfg': 64, 'guibg': 472642, 'guifg': 8755456}}, 'paste_indicator': {'n': {'ctermbg': 160, 'attr': 'bold', 'ctermfg': 230, 'guibg': 14430767, 'guifg': 16643811}}, 'ctrlp:marked': {'n': {'ctermbg': 234, 'attr': 'bold', 'ctermfg': 148, 'guibg': 11062, 'guifg': 11523840}}, 'scrollpercent': {'n': {'ctermbg': 236, 'attr': 'NONE', 'ctermfg': 245, 'guibg': 3158064, 'guifg': 9079434}, 'N': {'ctermbg': 235, 'attr': 'NONE', 'ctermfg': 254, 'guibg': 472642, 'guifg': 15657173}}, 'gundo:static_str.buffer': {'n': {'ctermbg': 235, 'attr': 'NONE', 'ctermfg': 231, 'guibg': 472642, 'guifg': 16777215}, 'N': {'ctermbg': 235, 'attr': 'NONE', 'ctermfg': 241, 'guibg': 472642, 'guifg': 6447714}}, 'fullcurrenttag': {'i': {'ctermbg': 235, 'attr': 'NONE', 'ctermfg': 117, 'guibg': 472642, 'guifg': 8902655}, 'n': {'ctermbg': 236, 'attr': 'NONE', 'ctermfg': 241, 'guibg': 3158064, 'guifg': 6447714}}, 'tagbar:static_str.buffer': {'n': {'ctermbg': 33, 'attr': 'NONE', 'ctermfg': 230, 'guibg': 2526162, 'guifg': 16643811}, 'N': {'ctermbg': 235, 'attr': 'NONE', 'ctermfg': 241, 'guibg': 472642, 'guifg': 6447714}}, 'SPLIT': {'n': {'ctermbg': 235, 'attr': 'NONE', 'ctermfg': 231, 'guibg': 472642, 'guifg': 16777215}, 'N': {'ctermbg': 235, 'attr': 'NONE', 'ctermfg': 231, 'guibg': 472642, 'guifg': 16777215}}, 'virtualenv:statusline': {'i': {'ctermbg': 235, 'attr': 'NONE', 'ctermfg': 117, 'guibg': 472642, 'guifg': 8902655}, 'n': {'ctermbg': 236, 'attr': 'NONE', 'ctermfg': 241, 'guibg': 3158064, 'guifg': 6447714}}, 'currenttag': {'i': {'ctermbg': 235, 'attr': 'NONE', 'ctermfg': 117, 'guibg': 472642, 'guifg': 8902655}, 'n': {'ctermbg': 236, 'attr': 'NONE', 'ctermfg': 241, 'guibg': 3158064, 'guifg': 6447714}}, 'nerdtree:raw.name': {'n': {'ctermbg': 24, 'attr': 'bold', 'ctermfg': 252, 'guibg': 24455, 'guifg': 13684944}, 'N': {'ctermbg': 235, 'attr': 'bold', 'ctermfg': 239, 'guibg': 472642, 'guifg': 5131854}}, 'ctrlp:focus': {'n': {'ctermbg': 234, 'attr': 'NONE', 'ctermfg': 64, 'guibg': 11062, 'guifg': 8755456}}, 'ctrlp:byfname': {'n': {'ctermbg': 234, 'attr': 'NONE', 'ctermfg': 64, 'guibg': 11062, 'guifg': 8755456}}, 'command_t:static_str.name': {'n': {'ctermbg': 31, 'attr': 'bold', 'ctermfg': 230, 'guibg': 34735, 'guifg': 16643811}, 'N': {'ctermbg': 234, 'attr': 'bold', 'ctermfg': 245, 'guibg': 11062, 'guifg': 9675169}}, 'lineinfo': {'n': {'ctermbg': 252, 'attr': 'bold', 'ctermfg': 236, 'guibg': 13684944, 'guifg': 3158064}, 'i': {'ctermbg': 117, 'attr': 'bold', 'ctermfg': 23, 'guibg': 8902655, 'guifg': 24415}, 'N': {'ctermbg': 235, 'attr': 'bold', 'ctermfg': 245, 'guibg': 2500134, 'guifg': 9079434}}, 'filetype': {'i': {'ctermbg': 235, 'attr': 'NONE', 'ctermfg': 117, 'guibg': 472642, 'guifg': 8902655}, 'n': {'ctermbg': 236, 'attr': 'NONE', 'ctermfg': 241, 'guibg': 3158064, 'guifg': 6447714}}, 'charcode': {'i': {'ctermbg': 235, 'attr': 'NONE', 'ctermfg': 117, 'guibg': 472642, 'guifg': 8902655}, 'n': {'ctermbg': 236, 'attr': 'NONE', 'ctermfg': 241, 'guibg': 3158064, 'guifg': 6447714}}, 'filepath': {'n': {'ctermbg': 24, 'attr': 'bold', 'ctermfg': 254, 'guibg': 24455, 'guifg': 15657173}, 'N': {'ctermbg': 235, 'attr': 'bold', 'ctermfg': 245, 'guibg': 472642, 'guifg': 9675169}}, 'fileinfo': {'n': {'ctermbg': 24, 'attr': 'bold', 'ctermfg': 254, 'guibg': 24455, 'guifg': 15657173}, 'N': {'ctermbg': 235, 'attr': 'bold', 'ctermfg': 245, 'guibg': 472642, 'guifg': 9675169}}, 'filename': {'n': {'ctermbg': 24, 'attr': 'bold', 'ctermfg': 254, 'guibg': 24455, 'guifg': 15657173}, 'N': {'ctermbg': 235, 'attr': 'bold', 'ctermfg': 245, 'guibg': 472642, 'guifg': 9675169}}, 'ctrlp:next': {'n': {'ctermbg': 235, 'attr': 'NONE', 'ctermfg': 64, 'guibg': 472642, 'guifg': 8755456}}, 'currhigroup': {'i': {'ctermbg': 235, 'attr': 'NONE', 'ctermfg': 117, 'guibg': 472642, 'guifg': 8902655}, 'n': {'ctermbg': 236, 'attr': 'NONE', 'ctermfg': 241, 'guibg': 3158064, 'guifg': 6447714}}, 'lustyexplorer:static_str.name': {'n': {'ctermbg': 24, 'attr': 'bold', 'ctermfg': 252, 'guibg': 24455, 'guifg': 13684944}, 'N': {'ctermbg': 235, 'attr': 'bold', 'ctermfg': 239, 'guibg': 472642, 'guifg': 5131854}}, 'ws_marker': {'n': {'ctermbg': 160, 'attr': 'bold', 'ctermfg': 230, 'guibg': 14430767, 'guifg': 16643811}}, 'minibufexplorer:static_str.name': {'n': {'ctermbg': 24, 'attr': 'bold', 'ctermfg': 252, 'guibg': 24455, 'guifg': 13684944}, 'N': {'ctermbg': 235, 'attr': 'bold', 'ctermfg': 239, 'guibg': 472642, 'guifg': 5131854}}, 'tagbar:SPLIT': {'n': {'ctermbg': 235, 'attr': 'NONE', 'ctermfg': 239, 'guibg': 472642, 'guifg': 5131854}, 'N': {'ctermbg': 235, 'attr': 'NONE', 'ctermfg': 239, 'guibg': 472642, 'guifg': 5131854}}, 'fileformat': {'i': {'ctermbg': 235, 'attr': 'NONE', 'ctermfg': 117, 'guibg': 472642, 'guifg': 8902655}, 'n': {'ctermbg': 236, 'attr': 'NONE', 'ctermfg': 241, 'guibg': 3158064, 'guifg': 6447714}}, 'lineinfo.line.tot': {'n': {'ctermbg': '', 'attr': 'NONE', 'ctermfg': 244, 'guibg': '', 'guifg': 8421504}, 'i': {'ctermbg': '', 'attr': 'NONE', 'ctermfg': 23, 'guibg': '', 'guifg': 24415}, 'N': {'ctermbg': '', 'attr': 'NONE', 'ctermfg': 241, 'guibg': '', 'guifg': 6447714}}, 'static_str': {'n': {'ctermbg': 61, 'attr': 'NONE', 'ctermfg': 230, 'guibg': 7107012, 'guifg': 16643811}, 'i': {'ctermbg': 235, 'attr': 'NONE', 'ctermfg': 231, 'guibg': 472642, 'guifg': 16777215}, 'N': {'ctermbg': 235, 'attr': 'NONE', 'ctermfg': 245, 'guibg': 472642, 'guifg': 9675169}}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment