Skip to content

Commit 37d343e

Browse files
committed
Added palette.pl
1 parent 2214927 commit 37d343e

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

README.md

+12
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,18 @@ Change the config.h file and you're good to go!
2121
The text background and foreground are respectively the first and the second
2222
entries in the palette (COLOR0 and COLOR1).
2323

24+
Colors
25+
------
26+
Attached there's palette.pl, an handy tool that extracts a palette from your
27+
X colors and returns it ready to be pasted in the configuration file.
28+
29+
```
30+
palette.pl <.Xresources / .Xdefaults path>
31+
```
32+
33+
If you keep your colors in a separate file just feed that file and you're good
34+
to go.
35+
2436
Text formatting
2537
---------------
2638
All the format commands are preceded by a backslash (\\).

palette.pl

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/bin/env perl
2+
#
3+
# palette.pl
4+
#
5+
# Converts your .Xdefault/.Xresources colors into a ready to paste palette
6+
# for bar. It takes your foreground/background settings into account and if
7+
# it cant find them it leaves COLOR0/COLOR1 undefined.
8+
#
9+
10+
use strict;
11+
use warnings;
12+
13+
open (F, "<".$ARGV[0]) || die "Can't open!";
14+
15+
while (<F>) {
16+
if ($_ =~ m/^\s*(?:\w+\.|\*)(color|background|foreground)(\d+)?\s*:\s*#([0-9A-Fa-f]*)/) {
17+
if ($1 eq "background") {
18+
printf "#define COLOR0\t0x$3\n";
19+
}
20+
elsif ($1 eq "foreground") {
21+
printf "#define COLOR1\t0x$3\n"
22+
}
23+
elsif ($1 eq "color" && $2 < 8) {
24+
printf "#define COLOR%i\t0x$3\n", $2 + 2;
25+
}
26+
}
27+
}

0 commit comments

Comments
 (0)