-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxcolors
executable file
·133 lines (93 loc) · 2.98 KB
/
xcolors
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#!/usr/bin/env perl -w
#
# xcolors: Find the X11 rgb.txt file.
#
# ???: Written by Steven J. DeRose.
# 2010-09-23 sjd: Clean up, Getopt, etc.
# 2013-04-18 sjd: Clean up. Add -grep/-find.
#
# To do:
#
use strict;
use Getopt::Long;
our $VERSION_DATE = "2013-04-18";
my $grep = "";
my $quiet = 0;
my $verbose = 0;
###############################################################################
#
Getopt::Long::Configure ("ignore_case");
my $result = GetOptions(
"grep|find=s" => \$grep,
"h|help" => sub { system "perldoc $0"; exit; },
"q!" => \$quiet,
"v+" => \$verbose,
"version" => sub {
die "Version of $VERSION_DATE, by Steven J. DeRose.\n";
},
);
($result) || die "Bad options.\n";
###############################################################################
# Main
#
my @paths = (
"/usr/share/X11/rgb.txt",
"/usr/X11R6/lib/X11/rgb.txt",
"/usr/X11R6/share/X11/rgb.txt".
"/usr/share/emacs/22.2/etc/rgb.txt",
"/etc/X11/rgb.txt",
"/host/Python25/Tools/pynche/X/rgb.txt",
"/host/cygwin/usr/share/emacs/23.0.92/etc/rgb.txt",
"/opt/X11/share/X11/rgb.txt",
);
if ($verbose) {
print "xcolors: Finds and displays the X Windows rgb.txt file, from:\n";
print " " . join("\n ",@paths) . "\n";
exit;
}
my $nFound = 0;
for my $path (@paths) {
if (-f $path) {
$nFound++;
warn "File found: $path\n";
open(XC, "<$path");
while (my $rec = <XC>) {
if (!$grep || $rec =~ m/$grep/i) { print $rec; }
}
close(XC);
}
}
($nFound) ||
die "Can't find X11 'rgb.txt' color file (use -v to see path checked).\n";
exit;
###############################################################################
###############################################################################
###############################################################################
#
=pod
=head1 Usage
xcolors [options] file
Show the X11 color-definition file. With I<--grep>, show only lines
that match the following regex.
=head1 Options
(prefix 'no' to negate where applicable)
=over
=item * B<--grep> I<regex> or B<--find> I<--regex>
Show only lines of the color file that match the given regex.
=item * B<--quiet> OR B<-q>
Suppress most messages, and avoid
printing the content of the rgb.txt file itself (just show the path).
=item * B<--verbose> OR B<-v>
Add more messages, including the entire
list of directories where the script tries to find rgc.txt.
=item * B<--version>
Show version info and exit.
=back
=head1 Related commands.
Pretty much the same as *nix C<showrgb>.
=head1 Ownership
This work by Steven J. DeRose is licensed under a Creative Commons
Attribution-Share Alike 3.0 Unported License. For further information on
this license, see L<http://creativecommons.org/licenses/by-sa/3.0/>.
For the most recent version, see L<http://www.derose.net/steve/utilities/>.
=cut