From 37d343e5540497e6d28ce9a807cb720d9101b615 Mon Sep 17 00:00:00 2001 From: LemonBoy Date: Wed, 18 Jul 2012 17:25:19 +0200 Subject: [PATCH] Added palette.pl --- README.md | 12 ++++++++++++ palette.pl | 27 +++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100755 palette.pl diff --git a/README.md b/README.md index 8a23cdb..3e44751 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,18 @@ Change the config.h file and you're good to go! The text background and foreground are respectively the first and the second entries in the palette (COLOR0 and COLOR1). +Colors +------ +Attached there's palette.pl, an handy tool that extracts a palette from your +X colors and returns it ready to be pasted in the configuration file. + +``` +palette.pl <.Xresources / .Xdefaults path> +``` + +If you keep your colors in a separate file just feed that file and you're good +to go. + Text formatting --------------- All the format commands are preceded by a backslash (\\). diff --git a/palette.pl b/palette.pl new file mode 100755 index 0000000..31e32f1 --- /dev/null +++ b/palette.pl @@ -0,0 +1,27 @@ +#!/usr/bin/env perl +# +# palette.pl +# +# Converts your .Xdefault/.Xresources colors into a ready to paste palette +# for bar. It takes your foreground/background settings into account and if +# it cant find them it leaves COLOR0/COLOR1 undefined. +# + +use strict; +use warnings; + +open (F, "<".$ARGV[0]) || die "Can't open!"; + +while () { + if ($_ =~ m/^\s*(?:\w+\.|\*)(color|background|foreground)(\d+)?\s*:\s*#([0-9A-Fa-f]*)/) { + if ($1 eq "background") { + printf "#define COLOR0\t0x$3\n"; + } + elsif ($1 eq "foreground") { + printf "#define COLOR1\t0x$3\n" + } + elsif ($1 eq "color" && $2 < 8) { + printf "#define COLOR%i\t0x$3\n", $2 + 2; + } + } +}