Added palette.pl

This commit is contained in:
LemonBoy 2012-07-18 17:25:19 +02:00
parent 2214927250
commit 37d343e554
2 changed files with 39 additions and 0 deletions

View File

@ -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 (\\).

27
palette.pl Executable file
View File

@ -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 (<F>) {
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;
}
}
}