acmecert: Added certificate expiry check command.
[utils.git] / lsanime
CommitLineData
03826bab
FT
1#!/usr/bin/perl
2
3use Getopt::Long;
4use Term::ReadKey;
5
6GetOptions(\%options, 'k', 'i', 't');
7
8if(@ARGV > 0) {
9 chdir($ARGV[0]);
10}
11while($dir = <*>) {
12 if(-d $dir) {
13 $fl = {};
14 if(-r "$dir/nextep") {
15 open NE, "$dir/nextep" || die;
16 $ne = "";
17 $ne += $_ while <NE>;
18 close NE;
19 if($ne == 1) {
20 $fl->{"first"} = 1;
21 } else {
22 $fl->{"act"} = 1;
23 }
24 $dirs{$dir} = $ne;
25 if(-r "$dir/.autodl/curep" && -r "$dir/.autodl/rtinfo") {
26 open DE, "$dir/.autodl/curep" || die;
27 $de = "";
28 $de += $_ while <DE>;
29 close DE;
30 if($ne < $de) {
31 $fl->{"hasmore"} = 1;
32 } else {
33 $fl->{"nomore"} = 1;
34 }
35 }
36 }
37 if(-r "$dir/.flags") {
38 open FL, "$dir/.flags" || die;
39 while(<FL>) {
40 chomp;
41 $fl->{$_} = 1;
42 }
43 close FL;
44 }
45 $dirs{$dir} = $fl;
46 }
47}
48if(! -t STDOUT) {
49 die "not on a tty";
50}
51for (keys %dirs) {
52 $cns = $options{"k"} == $dirs{$_}->{"kaka"};
53 # $cns = 0 if $dirs{$_}->{"notdone"} && !$options{"i"};
54 if($cns) {
55 if($dirs{$_}->{"lp"}) {
56 $nc = 31;
57 } elsif($dirs{$_}->{"first"}) {
58 $nc = 32;
59 } elsif($dirs{$_}->{"hasmore"}) {
60 $nc = 36;
61 } elsif($dirs{$_}->{"nomore"}) {
62 $nc = 35;
63 } elsif($dirs{$_}->{"act"}) {
64 $nc = 33;
65 } else {
66 $nc = 34;
67 }
68 } else {
69 $nc = 34;
70 }
71 if($options{"t"} && ($nc == 34)) {
72 delete $dirs{$_};
73 } else {
74 $dirs{$_}->{"color"} = $nc;
75 }
76}
77$cw = 0;
78for $d (keys %dirs) {
79 $l = length $d;
80 $cw = $l if $l > $cw;
81}
82$cw += 2;
83($w, $h) = GetTerminalSize;
84$cols = int($w / $cw);
85@sorted = sort keys %dirs;
86$percol = int(@sorted / $cols) + 1;
87for($i = 0; $i < $percol; $i++) {
88 for($o = 0, $x = 0; $o < $cols; $o++) {
89 $n = ($o * $percol) + $i;
90 last if $n >= @sorted;
91 print (" " x (($cw * $o) - $x)) if $x < $cw * $o;
92 $_ = $sorted[$n];
93 $x = $cw * $o;
94 $nc = $dirs{$_}->{"color"};
95 print "\e[${nc}m$_\e[39m";
96 $x += length;
97 }
98 print "\n";
99}