-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
lscolorpicker
executable file
·72 lines (62 loc) · 1.59 KB
/
lscolorpicker
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
#!/usr/bin/perl
# abstract: generate LS_COLORS interactively
use strict;
use Term::ExtendedColor qw(fg bg);
my $EXPORT;
my %ls_colors = (
normal => 'no',
file => 'fi',
dir => 'di',
link => 'ln',
pipe => 'pi',
door => 'do',
block => 'bd',
char => 'cd',
orphan => 'or',
socket => 'so',
setuid => 'su',
setgid => 'sg',
sticky_other_writable => 'tw',
other_writeable => 'ow',
sticky => 'st',
exec => 'ex',
missing => 'mi',
leftcode => 'lc',
rightcode => 'rc',
encode => 'ec', # non-filename tet
);
set_ls_color();
sub color_square {
select(STDERR);
for(0 .. 255) {
if($_ % 8 == 0) {
print "\n";
}
else {
printf ("%s%s", bg($_, sprintf(" %03d ", $_)));
}
}
print "\n";
}
sub set_ls_color {
select(STDERR);
$ENV{LS_COLORS} = '';
for my $f(keys(%ls_colors)) {
color_square();
printf("Color for %s: ", $f);
chomp(my $answer = <STDIN>);
#my $answer = 197;
if(valid_color($answer)) {
$EXPORT .= "$ls_colors{$f}=38;5;$answer:";
}
}
$EXPORT =~ s/^(.+):$/"$1"/;
select(STDOUT);
print "export LS_COLORS=\"ln=38;5;100;1:fi=38;5;196;1\"";
#print "$EXPORT\n";
}
sub valid_color {
my $color = shift;
return 1 if ( ($color =~ m/^\d+$/) and ($color < 256) and ($color > -1) );
return;
}