iterm stuff added to tree (and trackable)
This commit is contained in:
parent
705d6d4dc9
commit
1e0d8bdc07
1599 changed files with 99751 additions and 0 deletions
8
iterm2colors/tools/genMD.py
Executable file
8
iterm2colors/tools/genMD.py
Executable file
|
|
@ -0,0 +1,8 @@
|
|||
import os
|
||||
|
||||
with open('README.md', 'w') as mkdn:
|
||||
mkdn.write("Screenshots\n===\n")
|
||||
for f in [f for f in os.listdir('.') if os.path.isfile(f)]:
|
||||
mkdn.write("`%s`\n\n" % f)
|
||||
mkdn.write("\n\n" % f)
|
||||
|
||||
149
iterm2colors/tools/iterm2terminal.swift
Executable file
149
iterm2colors/tools/iterm2terminal.swift
Executable file
|
|
@ -0,0 +1,149 @@
|
|||
#!/usr/bin/env swift
|
||||
|
||||
import AppKit
|
||||
|
||||
enum iTermColors: String {
|
||||
case Ansi0 = "Ansi 0 Color"
|
||||
case Ansi1 = "Ansi 1 Color"
|
||||
case Ansi2 = "Ansi 2 Color"
|
||||
case Ansi3 = "Ansi 3 Color"
|
||||
case Ansi4 = "Ansi 4 Color"
|
||||
case Ansi5 = "Ansi 5 Color"
|
||||
case Ansi6 = "Ansi 6 Color"
|
||||
case Ansi7 = "Ansi 7 Color"
|
||||
case Ansi8 = "Ansi 8 Color"
|
||||
case Ansi9 = "Ansi 9 Color"
|
||||
case Ansi10 = "Ansi 10 Color"
|
||||
case Ansi11 = "Ansi 11 Color"
|
||||
case Ansi12 = "Ansi 12 Color"
|
||||
case Ansi13 = "Ansi 13 Color"
|
||||
case Ansi14 = "Ansi 14 Color"
|
||||
case Ansi15 = "Ansi 15 Color"
|
||||
case CursorText = "Cursor Text Color"
|
||||
case SelectedText = "Selected Text Color"
|
||||
case Foreground = "Foreground Color"
|
||||
case Background = "Background Color"
|
||||
case Bold = "Bold Color"
|
||||
case Selection = "Selection Color"
|
||||
case Cursor = "Cursor Color"
|
||||
}
|
||||
|
||||
enum TerminalColors: String {
|
||||
case AnsiBlack = "ANSIBlackColor"
|
||||
case AnsiRed = "ANSIRedColor"
|
||||
case AnsiGreen = "ANSIGreenColor"
|
||||
case AnsiYellow = "ANSIYellowColor"
|
||||
case AnsiBlue = "ANSIBlueColor"
|
||||
case AnsiMagenta = "ANSIMagentaColor"
|
||||
case AnsiCyan = "ANSICyanColor"
|
||||
case AnsiWhite = "ANSIWhiteColor"
|
||||
case AnsiBrightBlack = "ANSIBrightBlackColor"
|
||||
case AnsiBrightRed = "ANSIBrightRedColor"
|
||||
case AnsiBrightGreen = "ANSIBrightGreenColor"
|
||||
case AnsiBrightYellow = "ANSIBrightYellowColor"
|
||||
case AnsiBrightBlue = "ANSIBrightBlueColor"
|
||||
case AnsiBrightMagenta = "ANSIBrightMagentaColor"
|
||||
case AnsiBrightCyan = "ANSIBrightCyanColor"
|
||||
case AnsiBrightWhite = "ANSIBrightWhiteColor"
|
||||
case Background = "BackgroundColor"
|
||||
case Text = "TextColor"
|
||||
case BoldText = "TextBoldColor"
|
||||
case Selection = "SelectionColor"
|
||||
case Cursor = "CursorColor"
|
||||
}
|
||||
|
||||
let iTermColor2TerminalColor = [
|
||||
iTermColors.Ansi0: TerminalColors.AnsiBlack,
|
||||
iTermColors.Ansi1: TerminalColors.AnsiRed,
|
||||
iTermColors.Ansi2: TerminalColors.AnsiGreen,
|
||||
iTermColors.Ansi3: TerminalColors.AnsiYellow,
|
||||
iTermColors.Ansi4: TerminalColors.AnsiBlue,
|
||||
iTermColors.Ansi5: TerminalColors.AnsiMagenta,
|
||||
iTermColors.Ansi6: TerminalColors.AnsiCyan,
|
||||
iTermColors.Ansi7: TerminalColors.AnsiWhite,
|
||||
iTermColors.Ansi8: TerminalColors.AnsiBrightBlack,
|
||||
iTermColors.Ansi9: TerminalColors.AnsiBrightRed,
|
||||
iTermColors.Ansi10: TerminalColors.AnsiBrightGreen,
|
||||
iTermColors.Ansi11: TerminalColors.AnsiBrightYellow,
|
||||
iTermColors.Ansi12: TerminalColors.AnsiBrightBlue,
|
||||
iTermColors.Ansi13: TerminalColors.AnsiBrightMagenta,
|
||||
iTermColors.Ansi14: TerminalColors.AnsiBrightCyan,
|
||||
iTermColors.Ansi15: TerminalColors.AnsiBrightWhite,
|
||||
iTermColors.Background: TerminalColors.Background,
|
||||
iTermColors.Foreground: TerminalColors.Text,
|
||||
iTermColors.Selection: TerminalColors.Selection,
|
||||
iTermColors.Bold: TerminalColors.BoldText,
|
||||
iTermColors.Cursor: TerminalColors.Cursor,
|
||||
]
|
||||
|
||||
struct iTermColorComponent {
|
||||
static let Red = "Red Component"
|
||||
static let Green = "Green Component"
|
||||
static let Blue = "Blue Component"
|
||||
}
|
||||
|
||||
func itermColorSchemeToTerminalColorScheme(_ itermColorScheme: NSDictionary, name: String) -> NSDictionary {
|
||||
var terminalColorScheme: [String: AnyObject] = [
|
||||
"name" : name as AnyObject,
|
||||
"type" : "Window Settings" as AnyObject,
|
||||
"ProfileCurrentVersion" : 2.04 as AnyObject,
|
||||
"columnCount": 90 as AnyObject,
|
||||
"rowCount": 50 as AnyObject,
|
||||
]
|
||||
if let font = archivedFontWithName("PragmataPro", size: 14) {
|
||||
terminalColorScheme["Font"] = font as AnyObject?
|
||||
}
|
||||
for (rawKey, rawValue) in itermColorScheme {
|
||||
if let name = rawKey as? String {
|
||||
if let key = iTermColors(rawValue: name) {
|
||||
if let terminalKey = iTermColor2TerminalColor[key] {
|
||||
if let itermDict = rawValue as? [String: AnyObject] {
|
||||
let (r, g, b) = (
|
||||
floatValue(itermDict[iTermColorComponent.Red]),
|
||||
floatValue(itermDict[iTermColorComponent.Green]),
|
||||
floatValue(itermDict[iTermColorComponent.Blue]))
|
||||
let color = NSColor(deviceRed: r, green: g, blue: b, alpha: 1)
|
||||
let colorData = NSKeyedArchiver.archivedData(withRootObject: color)
|
||||
terminalColorScheme[terminalKey.rawValue] = colorData as AnyObject
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return terminalColorScheme as NSDictionary
|
||||
}
|
||||
|
||||
func archivedFontWithName(_ name: String, size: CGFloat) -> Data? {
|
||||
if let font = NSFont(name: name, size: size) {
|
||||
return NSKeyedArchiver.archivedData(withRootObject: font)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func floatValue(_ value: AnyObject?) -> CGFloat {
|
||||
if let num = value as? CGFloat {
|
||||
return num
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func convertToTerminalColors(_ itermFile: String, terminalFile: NSString) {
|
||||
if let itermScheme = NSDictionary(contentsOfFile: itermFile) {
|
||||
print("converting \(itermFile) -> \(terminalFile)")
|
||||
let terminalName = ((terminalFile.lastPathComponent) as NSString).deletingPathExtension
|
||||
let terminalScheme = itermColorSchemeToTerminalColorScheme(itermScheme, name: terminalName)
|
||||
terminalScheme.write(toFile: terminalFile as String, atomically: true)
|
||||
} else {
|
||||
print("unable to load \(itermFile)")
|
||||
}
|
||||
}
|
||||
|
||||
if CommandLine.argc > 1 {
|
||||
for itermFile in CommandLine.arguments {
|
||||
let terminalFilePath = (itermFile as NSString).deletingPathExtension + ".terminal"
|
||||
convertToTerminalColors(itermFile, terminalFile: terminalFilePath as NSString)
|
||||
}
|
||||
} else {
|
||||
print("usage: iTermColorsToTerminalColors FILE.itermcolors [...]")
|
||||
}
|
||||
|
||||
16
iterm2colors/tools/iterm2xrdb
Executable file
16
iterm2colors/tools/iterm2xrdb
Executable file
|
|
@ -0,0 +1,16 @@
|
|||
#!/usr/bin/env ruby
|
||||
#
|
||||
# Usage: iterm2xrdb FILE...
|
||||
# Usage: cat FILE... | iterm2xrdb
|
||||
# Usage: iterm2xrdb < INPUT
|
||||
#
|
||||
# Converts iTerm2 color schemes into xrdb(1) format, as a set of `#define`s,
|
||||
# and prints the result to STDOUT. Reads STDIN if no input files are given.
|
||||
#
|
||||
# Written in 2013 by Suraj N. Kurapati <https://github.com/sunaku>
|
||||
|
||||
puts ARGF.read.scan(%r{>(.+?)</}).flatten(1).slice_before(/\bColor$/).map {
|
||||
|color, *pairs| "#define #{ color.gsub(/\W/, ?_) } #" + Hash[*pairs].
|
||||
values_at('Red Component', 'Green Component', 'Blue Component').
|
||||
map { |intensity| sprintf '%02x', (intensity.to_f * 255).round }.join
|
||||
}.to_a
|
||||
76
iterm2colors/tools/preview.rb
Executable file
76
iterm2colors/tools/preview.rb
Executable file
|
|
@ -0,0 +1,76 @@
|
|||
#!/usr/bin/ruby
|
||||
#
|
||||
# Applies the colors defined in .itermcolors file to the current session using
|
||||
# proprietary escape codes of iTerm2
|
||||
#
|
||||
# Author: Junegunn Choi <https://github.com/junegunn> Reference:
|
||||
# https://iterm2.com/documentation-escape-codes.html
|
||||
|
||||
require 'rexml/document'
|
||||
require 'io/console'
|
||||
|
||||
files = ARGV.select { |f| File.exists? f }
|
||||
if files.empty?
|
||||
puts "usage: #$0 <itermcolors files...>"
|
||||
exit 1
|
||||
end
|
||||
|
||||
if ENV.has_key? 'TMUX'
|
||||
puts 'Does not work on tmux'
|
||||
exit 1
|
||||
end
|
||||
|
||||
preview = files.length > 1
|
||||
history = []
|
||||
until files.empty?
|
||||
file = files.shift
|
||||
print "[#{File.basename file, '.*'}] " if preview
|
||||
begin
|
||||
colors = {}
|
||||
root = REXML::Document.new(File.read file).root
|
||||
root.elements['dict'].select { |e| e.is_a? REXML::Element }.each do |dict|
|
||||
if dict.previous_element && !dict.previous_element.text.strip.empty?
|
||||
type = dict.previous_element.text.downcase.gsub(/^ansi\s+|\s+color$/, '')
|
||||
colors[type] = {}
|
||||
end
|
||||
next unless type
|
||||
|
||||
dict.elements.each_slice(2) do |elems|
|
||||
key = val = nil
|
||||
elems.each do |elem|
|
||||
case elem.name.downcase
|
||||
when 'key' then key = elem.text
|
||||
when 'real' then val = elem.text
|
||||
end
|
||||
end
|
||||
colors[type][key.sub(/\s.+/, '').downcase.to_sym] =
|
||||
'%02x' % [255, val.to_f.*(256).to_i].min if key && val
|
||||
end
|
||||
colors[type] &&= colors[type].values_at(:red, :green, :blue).join
|
||||
end
|
||||
|
||||
colors.each do |type, rgb|
|
||||
print "\e]P" << {
|
||||
'foreground' => 'g',
|
||||
'background' => 'h',
|
||||
'bold' => 'i',
|
||||
'selection' => 'j',
|
||||
'selected text' => 'k',
|
||||
'cursor' => 'l',
|
||||
'cursor text' => 'm',
|
||||
}.fetch(type, '%x' % type.to_i) << rgb << "\e\\"
|
||||
end
|
||||
case IO.console.getch.ord
|
||||
when 127 # backspace
|
||||
files.unshift *[history.pop, file].compact
|
||||
when 3, 27 # ctrl-c, esc
|
||||
break
|
||||
else
|
||||
history << file
|
||||
end
|
||||
rescue Exception
|
||||
print '(X) '
|
||||
end
|
||||
end
|
||||
puts if preview
|
||||
|
||||
26
iterm2colors/tools/screenshotTable.sh
Executable file
26
iterm2colors/tools/screenshotTable.sh
Executable file
|
|
@ -0,0 +1,26 @@
|
|||
#!/bin/bash
|
||||
#
|
||||
# This file echoes a bunch of color codes to the
|
||||
# terminal to demonstrate what's available. Each
|
||||
# line is the color code of one forground color,
|
||||
# out of 17 (default + 16 escapes), followed by a
|
||||
# test use of that color on all nine background
|
||||
# colors (default + 8 escapes).
|
||||
#
|
||||
|
||||
T='gYw' # The test text
|
||||
|
||||
echo -e "\n 40m 41m 42m 43m\
|
||||
44m 45m 46m 47m";
|
||||
|
||||
for FGs in ' m' ' 1m' ' 30m' '1;30m' ' 31m' '1;31m' ' 32m' \
|
||||
'1;32m' ' 33m' '1;33m' ' 34m' '1;34m' ' 35m' '1;35m' \
|
||||
' 36m' '1;36m' ' 37m' '1;37m';
|
||||
do FG=${FGs// /}
|
||||
echo -en " $FGs \033[$FG $T "
|
||||
for BG in 40m 41m 42m 43m 44m 45m 46m 47m;
|
||||
do echo -en "$EINS \033[$FG\033[$BG $T \033[0m";
|
||||
done
|
||||
echo;
|
||||
done
|
||||
echo
|
||||
33
iterm2colors/tools/update_all.py
Executable file
33
iterm2colors/tools/update_all.py
Executable file
|
|
@ -0,0 +1,33 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import subprocess
|
||||
from glob import glob
|
||||
|
||||
from os.path import basename, splitext, join
|
||||
|
||||
import xrdb2konsole
|
||||
import xrdb2terminator
|
||||
import xrdb2Xresources
|
||||
import xrdb2putty
|
||||
import xrdb2xfce_terminal
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
for f in glob("../schemes/*.itermcolors"):
|
||||
base_name = splitext(basename(f))[0]
|
||||
xrdb_filepath = join('../xrdb', base_name + '.xrdb')
|
||||
with open(xrdb_filepath, 'w') as fout:
|
||||
ret_code = subprocess.Popen(['./iterm2xrdb', f], stdout=fout).wait()
|
||||
print(ret_code and "ERROR" or "OK" + " --> " + xrdb_filepath)
|
||||
|
||||
print()
|
||||
xrdb2konsole.main('../xrdb/', '../konsole/')
|
||||
print('OK --> ' + '../konsole/')
|
||||
xrdb2terminator.main('../xrdb/', '../terminator/')
|
||||
print('OK --> ' + '../terminator/')
|
||||
xrdb2Xresources.main('../xrdb/', '../Xresources/')
|
||||
print('OK --> ' + '../Xresources/')
|
||||
xrdb2putty.main('../xrdb/', '../putty/')
|
||||
print('OK --> ' + '../putty/')
|
||||
xrdb2xfce_terminal.main('../xrdb/', '../xfce4terminal/colorschemes/')
|
||||
print('OK --> ' + '../xfce4terminal/colorschemes/')
|
||||
129
iterm2colors/tools/xrdb2Xresources.py
Executable file
129
iterm2colors/tools/xrdb2Xresources.py
Executable file
|
|
@ -0,0 +1,129 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
import argparse
|
||||
from collections import OrderedDict
|
||||
|
||||
import sys
|
||||
from glob import glob
|
||||
|
||||
from os.path import join, splitext, basename
|
||||
|
||||
PREFIXES = ('XTerm', 'Rxvt', 'Urxvt')
|
||||
|
||||
|
||||
XRDB2XRES = [
|
||||
("# Head", "\n" "! Generated with :"
|
||||
"\n" "! XRDB2Xreources.py"
|
||||
"\n" "! "),
|
||||
("foreground_color", "*.foreground: "),
|
||||
("background_color", "*.background: "),
|
||||
("cursor_color", "*.cursorColor: "),
|
||||
|
||||
("# Black", "\n" "! Black"),
|
||||
("ansi_0_color", "*.color0: "),
|
||||
("ansi_8_color", "*.color8: "),
|
||||
|
||||
("# Red", "\n" "! Red"),
|
||||
("ansi_1_color", "*.color1: "),
|
||||
("ansi_9_color", "*.color9: "),
|
||||
|
||||
("# Green", "\n" "! Green"),
|
||||
("ansi_2_color", "*.color2: "),
|
||||
("ansi_10_color", "*.color10: "),
|
||||
|
||||
("# Yellow", "\n" "! Yellow"),
|
||||
("ansi_3_color", "*.color3: "),
|
||||
("ansi_11_color", "*.color11: "),
|
||||
|
||||
("# Blue", "\n" "! Blue"),
|
||||
("ansi_4_color", "*.color4: "),
|
||||
("ansi_12_color", "*.color12: "),
|
||||
|
||||
("# Magenta", "\n" "! Magenta"),
|
||||
("ansi_5_color", "*.color5: "),
|
||||
("ansi_13_color", "*.color13: "),
|
||||
|
||||
("# Cyan", "\n" "! Cyan"),
|
||||
("ansi_6_color", "*.color6: "),
|
||||
("ansi_14_color", "*.color14: "),
|
||||
|
||||
("# White", "\n" "! White"),
|
||||
("ansi_7_color", "*.color7: "),
|
||||
("ansi_15_color", "*.color15: "),
|
||||
|
||||
("# Bold", "\n" "! Bold, Italic, Underline"),
|
||||
("bold_color", "*.colorBD: "),
|
||||
("italic_color", "*.colorIT: "),
|
||||
("underline_color", "*.colorUL: "),
|
||||
]
|
||||
|
||||
|
||||
class XrdbEntry(object):
|
||||
def __init__(self, define: str, key: str, value: str, *args: str):
|
||||
super().__init__()
|
||||
self.define = define
|
||||
self.key = key.lower()
|
||||
self.value = value
|
||||
|
||||
def commented(self):
|
||||
return self.define.strip().startswith("!")
|
||||
|
||||
|
||||
def convert(xrdb_colors, x_resources_out=sys.stdout):
|
||||
x_resources = OrderedDict(XRDB2XRES)
|
||||
|
||||
for xrdb_key in x_resources.keys():
|
||||
if xrdb_key in xrdb_colors:
|
||||
x_resources[xrdb_key] = x_resources[xrdb_key] + xrdb_colors[xrdb_key]
|
||||
else:
|
||||
x_resources[xrdb_key] = "!" + x_resources[xrdb_key]
|
||||
|
||||
try:
|
||||
f = x_resources_out
|
||||
if not hasattr(f, 'close'):
|
||||
f = open(x_resources_out, 'w')
|
||||
|
||||
for value in x_resources.values():
|
||||
print(value.strip(), file=f)
|
||||
finally:
|
||||
if f != sys.stdout:
|
||||
f.close()
|
||||
|
||||
|
||||
def read_xrdb(itermcolors_input=sys.stdin):
|
||||
xrdb_colors = dict()
|
||||
|
||||
try:
|
||||
f = itermcolors_input
|
||||
if not hasattr(f, 'close'):
|
||||
f = open(itermcolors_input, 'r')
|
||||
|
||||
for line in f:
|
||||
xrdb_entry = XrdbEntry(*line.split())
|
||||
if not xrdb_entry.commented():
|
||||
xrdb_colors.setdefault(xrdb_entry.key, xrdb_entry.value)
|
||||
finally:
|
||||
f.close()
|
||||
|
||||
return xrdb_colors
|
||||
|
||||
|
||||
def main(xrdb_path, output_path=None):
|
||||
for f in glob(join(xrdb_path, '*.xrdb')):
|
||||
xrdb_in = read_xrdb(f)
|
||||
base_name = splitext(basename(f))[0]
|
||||
x_resources_out = output_path and join(output_path, base_name) or sys.stdout
|
||||
convert(xrdb_in, x_resources_out)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
parser = argparse.ArgumentParser(
|
||||
description='Translate X color schemes to .Xresources format')
|
||||
parser.add_argument('xrdb_path', type=str, help='path to xrdb files')
|
||||
parser.add_argument('-d', '--out-directory', type=str, dest='output_path',
|
||||
help='path where Xresources config files will be' +
|
||||
' created, if not provided then will be printed')
|
||||
|
||||
args = parser.parse_args()
|
||||
main(args.xrdb_path, args.output_path)
|
||||
53
iterm2colors/tools/xrdb2hterm
Executable file
53
iterm2colors/tools/xrdb2hterm
Executable file
|
|
@ -0,0 +1,53 @@
|
|||
#!/usr/bin/env ruby
|
||||
#
|
||||
# Converts xrdb(1) color schemes into Chrome Secure Shell preferences format
|
||||
# and prints the result to STDOUT. Reads STDIN if no input files are given.
|
||||
#
|
||||
# Usage: xrdb2hterm FILE...
|
||||
# Usage: cat FILE... | xrdb2hterm
|
||||
# Usage: xrdb2hterm < INPUT
|
||||
#
|
||||
#--
|
||||
# Written in 2014 by Suraj N. Kurapati <https://github.com/sunaku>
|
||||
|
||||
# expand preprocessor definitions
|
||||
input = DATA.read + ARGF.read
|
||||
defines = Hash[ input.scan /\#define\s+(\w+)\s+(.*)\s*/ ]
|
||||
while defines.any? {|k,v| input.gsub! k, v } do end
|
||||
|
||||
# convert xrdb(1) colors to hterm
|
||||
xrdb = Hash[ input.scan /(\w+)\s*:\s*(.*)\s*/ ]
|
||||
puts <<HTERM
|
||||
term_.prefs_.set("background-color", "#{ xrdb['background'] }");
|
||||
term_.prefs_.set("foreground-color", "#{ xrdb['foreground'] }");
|
||||
term_.prefs_.set("cursor-color", "rgba(#{
|
||||
xrdb['cursorColor'].scan(/\h{2}/).map {|s| s.to_i 16 }.join(?,)
|
||||
}, 0.5)"); /* #{ xrdb['cursorColor'] } */
|
||||
term_.prefs_.set("color-palette-overrides", #{
|
||||
(0..15).map {|i| xrdb["color#{i}"] }
|
||||
});
|
||||
HTERM
|
||||
|
||||
__END__
|
||||
*color0 : Ansi_0_Color
|
||||
*color1 : Ansi_1_Color
|
||||
*color2 : Ansi_2_Color
|
||||
*color3 : Ansi_3_Color
|
||||
*color4 : Ansi_4_Color
|
||||
*color5 : Ansi_5_Color
|
||||
*color6 : Ansi_6_Color
|
||||
*color7 : Ansi_7_Color
|
||||
*color8 : Ansi_8_Color
|
||||
*color9 : Ansi_9_Color
|
||||
*color10 : Ansi_10_Color
|
||||
*color11 : Ansi_11_Color
|
||||
*color12 : Ansi_12_Color
|
||||
*color13 : Ansi_13_Color
|
||||
*color14 : Ansi_14_Color
|
||||
*color15 : Ansi_15_Color
|
||||
*colorBD : Bold_Color
|
||||
*colorIT : Italic_Color
|
||||
*colorUL : Underline_Color
|
||||
*foreground : Foreground_Color
|
||||
*background : Background_Color
|
||||
*cursorColor : Cursor_Color
|
||||
101
iterm2colors/tools/xrdb2konsole.py
Executable file
101
iterm2colors/tools/xrdb2konsole.py
Executable file
|
|
@ -0,0 +1,101 @@
|
|||
#!/usr/bin/env python
|
||||
# coding: utf-8
|
||||
#
|
||||
# This script converts xrdb (X11) color scheme format to Konsole color
|
||||
# scheme format
|
||||
#
|
||||
# Usage:
|
||||
# xrdb2konsole.py path/to/xrdb/files -d /konsole/schemes/output
|
||||
#
|
||||
# Author: Stéphane Travostino
|
||||
# Adapted from xrdb2terminator by Xabier Larrakoetxea
|
||||
|
||||
import os
|
||||
import sys
|
||||
import re
|
||||
import argparse
|
||||
|
||||
# Takes #000A0B and returns (0, 10, 11)
|
||||
|
||||
def hex_to_rgb(color):
|
||||
return (int(color[1:3], 16), int(color[3:5], 16), int(color[5:7], 16))
|
||||
|
||||
|
||||
def build_konsole_color(name, r, g, b):
|
||||
return "[%s]\nColor=%d,%d,%d\n\n" % (name, r, g, b)
|
||||
|
||||
|
||||
def main(xrdb_path, output_path=None):
|
||||
|
||||
global xrdb_regex
|
||||
# The regexes to match the colors
|
||||
color_regex = re.compile("#define +Ansi_(\d+)_Color +(#[A-Fa-f0-9]{6})")
|
||||
bg_regex = re.compile("#define +Background_Color +(#[A-Fa-f0-9]{6})")
|
||||
fg_regex = re.compile("#define +Foreground_Color +(#[A-Fa-f0-9]{6})")
|
||||
bold_regex = re.compile("#define +Bold_Color +(#[A-Fa-f0-9]{6})")
|
||||
cursor_regex = re.compile("#define +Cursor_Color +(#[A-Fa-f0-9]{6})")
|
||||
|
||||
# File regex
|
||||
xrdb_regex = re.compile("(.+)\.[xX][rR][dD][bB]")
|
||||
for i in filter(lambda x: xrdb_regex.match(x), os.listdir(xrdb_path)):
|
||||
name = xrdb_regex.match(i).group(1)
|
||||
|
||||
# Read XRDB file
|
||||
with open(os.path.join(xrdb_path, i)) as f:
|
||||
xrdb_data = f.read()
|
||||
|
||||
# Open output file
|
||||
output = sys.stdout
|
||||
|
||||
if output_path:
|
||||
dest = os.path.join(output_path, name)
|
||||
output = open('{0}.colorscheme'.format(dest), 'w+')
|
||||
else:
|
||||
output.write('\n%s:\n' % name)
|
||||
|
||||
# Emit header
|
||||
output.write("[General]\nDescription=%s\nOpacity=1\nWallpaper=\n\n" % name)
|
||||
|
||||
# Emit background color
|
||||
bg_color = hex_to_rgb(bg_regex.search(xrdb_data).group(1))
|
||||
output.write(build_konsole_color('Background', *bg_color))
|
||||
output.write(build_konsole_color('BackgroundIntense', *bg_color))
|
||||
|
||||
# Emit foreground color
|
||||
fg_color = hex_to_rgb(fg_regex.search(xrdb_data).group(1))
|
||||
output.write(build_konsole_color('Foreground', *fg_color))
|
||||
|
||||
# Emit bold color, if any
|
||||
match = bold_regex.search(xrdb_data)
|
||||
if match:
|
||||
bold_color = hex_to_rgb(match.group(1))
|
||||
output.write(build_konsole_color('ForegroundIntense', *bold_color))
|
||||
else:
|
||||
output.write(build_konsole_color('ForegroundIntense', *fg_color))
|
||||
|
||||
# Emit other colors
|
||||
for match in color_regex.findall(xrdb_data):
|
||||
color_index = int(match[0])
|
||||
color_rgb = hex_to_rgb(match[1])
|
||||
|
||||
color_name = 'Color%d' % color_index if color_index < 8 else 'Color%dIntense' % (
|
||||
color_index - 8)
|
||||
|
||||
output.write(build_konsole_color(color_name, *color_rgb))
|
||||
|
||||
if output_path:
|
||||
output.close()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
parser = argparse.ArgumentParser(
|
||||
description='Translate X color schemes to termiantor format')
|
||||
parser.add_argument('xrdb_path', type=str, help='path to xrdb files')
|
||||
parser.add_argument('-d', '--out-directory', type=str, dest='output_path',
|
||||
help='path where terminator config files will be' +
|
||||
' created, if not provided then will be printed')
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
main(args.xrdb_path, args.output_path)
|
||||
129
iterm2colors/tools/xrdb2putty.py
Executable file
129
iterm2colors/tools/xrdb2putty.py
Executable file
|
|
@ -0,0 +1,129 @@
|
|||
#!/usr/bin/env python
|
||||
# coding: utf-8
|
||||
#
|
||||
# This script converts xrdb (X11) color scheme format to PuTTY registry
|
||||
# file which creates a new session with proper colors.
|
||||
#
|
||||
# Usage:
|
||||
# xrdb2putty.py path/to/xrdb/files -d path/to/putty/files
|
||||
#
|
||||
# Author: Caesar Kabalan <caesar.kabalan@gmail.com>
|
||||
# Adapted from xrdb2konsole by Stéphane Travostino
|
||||
# Adapted from xrdb2terminator by Xabier Larrakoetxea
|
||||
|
||||
import os
|
||||
import sys
|
||||
import re
|
||||
import argparse
|
||||
|
||||
# Takes #000A0B and returns (0, 10, 11)
|
||||
def hex_to_rgb(color):
|
||||
return (int(color[1:3], 16), int(color[3:5], 16), int(color[5:7], 16))
|
||||
|
||||
def build_putty_color(name, r, g, b):
|
||||
return "\"%s\"=\"%d,%d,%d\"\n" % (name, r, g, b)
|
||||
|
||||
def main(xrdb_path, output_path=None):
|
||||
|
||||
# The regexes to match the colors
|
||||
color_regex = re.compile("#define +Ansi_(\d+)_Color +(#[A-Fa-f0-9]{6})")
|
||||
bg_regex = re.compile("#define +Background_Color +(#[A-Fa-f0-9]{6})")
|
||||
fg_regex = re.compile("#define +Foreground_Color +(#[A-Fa-f0-9]{6})")
|
||||
bold_regex = re.compile("#define +Bold_Color +(#[A-Fa-f0-9]{6})")
|
||||
cursor_regex = re.compile("#define +Cursor_Color +(#[A-Fa-f0-9]{6})")
|
||||
cursor_text_regex = re.compile("#define +Cursor_Text_Color +(#[A-Fa-f0-9]{6})")
|
||||
|
||||
# File regex
|
||||
xrdb_regex = re.compile("(.+)\.[xX][rR][dD][bB]")
|
||||
|
||||
for i in filter(lambda x: xrdb_regex.match(x), os.listdir(xrdb_path)):
|
||||
name = xrdb_regex.match(i).group(1)
|
||||
|
||||
# Read XRDB file
|
||||
with open(os.path.join(xrdb_path, i)) as f:
|
||||
xrdb_data = f.read()
|
||||
|
||||
# Open output file
|
||||
output = sys.stdout
|
||||
|
||||
if output_path:
|
||||
dest = os.path.join(output_path, name)
|
||||
output = open('{0}.reg'.format(dest), 'w+')
|
||||
else:
|
||||
output.write('\n%s:\n' % name)
|
||||
|
||||
# Emit header
|
||||
output.write("Windows Registry Editor Version 5.00\n\n[HKEY_CURRENT_USER\Software\SimonTatham\PuTTY\Sessions\%s]\n" % name)
|
||||
|
||||
# Emit background color
|
||||
bg_color = hex_to_rgb(bg_regex.search(xrdb_data).group(1))
|
||||
output.write(build_putty_color('Colour2', *bg_color))
|
||||
output.write(build_putty_color('Colour3', *bg_color))
|
||||
|
||||
# Emit foreground color
|
||||
fg_color = hex_to_rgb(fg_regex.search(xrdb_data).group(1))
|
||||
output.write(build_putty_color('Colour0', *fg_color))
|
||||
|
||||
# Emit bold color, if any
|
||||
match = bold_regex.search(xrdb_data)
|
||||
if match:
|
||||
bold_color = hex_to_rgb(match.group(1))
|
||||
output.write(build_putty_color('Colour1', *bold_color))
|
||||
else:
|
||||
output.write(build_putty_color('Colour1', *fg_color))
|
||||
|
||||
# Emit cursor color
|
||||
cursor_color = hex_to_rgb(cursor_regex.search(xrdb_data).group(1))
|
||||
output.write(build_putty_color('Colour5', *cursor_color))
|
||||
|
||||
# Emit cursor text color
|
||||
cursor_text_color = hex_to_rgb(cursor_text_regex.search(xrdb_data).group(1))
|
||||
output.write(build_putty_color('Colour4', *cursor_text_color))
|
||||
|
||||
# The ANSI color list from xrdb doesn't match up with the weird order
|
||||
# that the putty registry entries use. This converts Ansi_0_Color from
|
||||
# .xrdb files to Colour6 which go into the PuTTY .reg files.
|
||||
xrdb_to_putty_dict = {
|
||||
0 : 6,
|
||||
1 : 8,
|
||||
2 : 10,
|
||||
3 : 12,
|
||||
4 : 14,
|
||||
5 : 16,
|
||||
6 : 18,
|
||||
7 : 20,
|
||||
8 : 7,
|
||||
9 : 9,
|
||||
10 : 11,
|
||||
11 : 13,
|
||||
12 : 15,
|
||||
13 : 17,
|
||||
14 : 19,
|
||||
15 : 21,
|
||||
}
|
||||
|
||||
# Emit other colors
|
||||
for match in color_regex.findall(xrdb_data):
|
||||
color_index = int(match[0])
|
||||
color_rgb = hex_to_rgb(match[1])
|
||||
|
||||
color_name = 'Colour%d' % xrdb_to_putty_dict[color_index]
|
||||
|
||||
output.write(build_putty_color(color_name, *color_rgb))
|
||||
|
||||
if output_path:
|
||||
output.close()
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
parser = argparse.ArgumentParser(
|
||||
description='Translate X color schemes to termiantor format')
|
||||
parser.add_argument('xrdb_path', type=str, help='path to xrdb files')
|
||||
parser.add_argument('-d', '--out-directory', type=str, dest='output_path',
|
||||
help='path where putty config files will be' +
|
||||
' created, if not provided then will be printed')
|
||||
|
||||
args = parser.parse_args()
|
||||
main(args.xrdb_path, args.output_path)
|
||||
|
||||
|
||||
79
iterm2colors/tools/xrdb2terminator.py
Executable file
79
iterm2colors/tools/xrdb2terminator.py
Executable file
|
|
@ -0,0 +1,79 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
# This script converts xrdb (X11) color scheme format to terminator color
|
||||
# scheme format
|
||||
#
|
||||
# Usage:
|
||||
# xrdb2terminator.py path/to/xrdb/files -d /terminator/schemes/output
|
||||
#
|
||||
# Author: Xabier Larrakoetxea
|
||||
|
||||
import os
|
||||
import re
|
||||
import argparse
|
||||
|
||||
|
||||
def main(xrdb_path, output_path=None):
|
||||
global color_regex, xrdb_regex
|
||||
# The regexes to match the colors
|
||||
color_regex = re.compile("#define +Ansi_(\d+)_Color +(#[A-Fa-f0-9]{6})")
|
||||
bg_regex = re.compile("#define +Background_Color +(#[A-Fa-f0-9]{6})")
|
||||
fg_regex = re.compile("#define +Foreground_Color +(#[A-Fa-f0-9]{6})")
|
||||
cursor_regex = re.compile("#define +Cursor_Color +(#[A-Fa-f0-9]{6})")
|
||||
# File regex
|
||||
xrdb_regex = re.compile("(.+)\.[xX][rR][dD][bB]")
|
||||
for i in filter(lambda x: xrdb_regex.match(x), os.listdir(xrdb_path)):
|
||||
|
||||
# per file
|
||||
with open(os.path.join(xrdb_path, i)) as f:
|
||||
lines = f.readlines()
|
||||
|
||||
# Search special colors
|
||||
color_file = "\n".join(lines)
|
||||
|
||||
bg_color = bg_regex.search(color_file).group(1)
|
||||
fg_color = fg_regex.search(color_file).group(1)
|
||||
cursor_color = cursor_regex.search(color_file).group(1)
|
||||
|
||||
# Search palette
|
||||
colors = sorted(filter(lambda x: color_regex.match(x), lines),
|
||||
key=lambda x: int(color_regex.match(x).group(1)))
|
||||
|
||||
# Create the color string
|
||||
colors = ":".join(map(lambda x: color_regex.match(x).group(2), colors))
|
||||
|
||||
scheme = """
|
||||
[[{name}]]
|
||||
palette = "{pl}"
|
||||
background_color = "{bg}"
|
||||
cursor_color = "{cr}"
|
||||
foreground_color = "{fg}"
|
||||
background_image = None
|
||||
"""
|
||||
|
||||
output = scheme.format(name=xrdb_regex.match(i).group(1),
|
||||
pl=colors,
|
||||
bg=bg_color,
|
||||
cr=cursor_color,
|
||||
fg=fg_color)
|
||||
|
||||
if not output_path:
|
||||
print(output)
|
||||
else:
|
||||
dest = os.path.join(output_path, xrdb_regex.match(i).group(1))
|
||||
with open('{0}.config'.format(dest), 'w+') as f:
|
||||
f.write(output)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
parser = argparse.ArgumentParser(
|
||||
description='Translate X color schemes to termiantor format')
|
||||
parser.add_argument('xrdb_path', type=str, help='path to xrdb files')
|
||||
parser.add_argument('-d', '--destiny', type=str, dest='output_path',
|
||||
help='path where terminator config files will be' +
|
||||
' created, if not provided then will be printed')
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
main(args.xrdb_path, args.output_path)
|
||||
82
iterm2colors/tools/xrdb2xfce_terminal.py
Executable file
82
iterm2colors/tools/xrdb2xfce_terminal.py
Executable file
|
|
@ -0,0 +1,82 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
# This script converts xrdb (X11) color scheme format to terminator color
|
||||
# scheme format
|
||||
#
|
||||
# Usage:
|
||||
# xrdb2xfce_terminal.py path/to/xrdb/files -d /xfce4terminal/colorschemes/output
|
||||
#
|
||||
# Based of xrdb2terminator by Xabier Larrakoetxea
|
||||
# Patched by Konstantin Artyushkin
|
||||
|
||||
import os
|
||||
import sys
|
||||
import re
|
||||
import argparse
|
||||
|
||||
def main(xrdb_path, output_path=None):
|
||||
|
||||
# The regexes to match the colors
|
||||
color_regex = re.compile("#define +Ansi_(\d+)_Color +(#[A-Fa-f0-9]{6})")
|
||||
bg_regex = re.compile("#define +Background_Color +(#[A-Fa-f0-9]{6})")
|
||||
fg_regex = re.compile("#define +Foreground_Color +(#[A-Fa-f0-9]{6})")
|
||||
cursor_regex = re.compile("#define +Cursor_Color +(#[A-Fa-f0-9]{6})")
|
||||
|
||||
# File regex
|
||||
xrdb_regex = re.compile("(.+)\.[xX][rR][dD][bB]")
|
||||
|
||||
for i in filter(lambda x: xrdb_regex.match(x), os.listdir(xrdb_path)):
|
||||
|
||||
# per file
|
||||
with open(os.path.join(xrdb_path, i)) as f:
|
||||
lines = f.readlines()
|
||||
|
||||
# Search special colors
|
||||
color_file = "\n".join(lines)
|
||||
|
||||
bg_color = bg_regex.search(color_file).group(1)
|
||||
fg_color = fg_regex.search(color_file).group(1)
|
||||
cursor_color = cursor_regex.search(color_file).group(1)
|
||||
|
||||
# Search palette
|
||||
colors = sorted(filter(lambda x: color_regex.match(x), lines),
|
||||
key=lambda x: int(color_regex.match(x).group(1)))
|
||||
|
||||
# Create the color string
|
||||
colors = ";".join(map(lambda x: color_regex.match(x).group(2), colors))
|
||||
|
||||
scheme = """
|
||||
[Scheme]
|
||||
Name={name}
|
||||
ColorForeground={fg}
|
||||
ColorBackground={bg}
|
||||
ColorCursor={cr}
|
||||
ColorPalette={pl}
|
||||
"""
|
||||
|
||||
output = scheme.format(name=xrdb_regex.match(i).group(1),
|
||||
pl=colors,
|
||||
bg=bg_color,
|
||||
cr=cursor_color,
|
||||
fg=fg_color)
|
||||
|
||||
if not output_path:
|
||||
print(output)
|
||||
else:
|
||||
dest = os.path.join(output_path, xrdb_regex.match(i).group(1))
|
||||
with open('{0}.theme'.format(dest), 'w+') as f:
|
||||
f.write(output)
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
parser = argparse.ArgumentParser(
|
||||
description='Translate X color schemes to termiantor format')
|
||||
parser.add_argument('xrdb_path', type=str, help='path to xrdb files')
|
||||
parser.add_argument('-d', '--destiny', type=str, dest='output_path',
|
||||
help='path where terminator config files will be' +
|
||||
' created, if not provided then will be printed')
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
main(args.xrdb_path, args.output_path)
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue