Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
executable file 72 lines (61 sloc) 1.55 KB
#!/usr/bin/perl
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;
}