From: Fredrik Tolf Date: Fri, 30 Jul 2010 18:14:37 +0000 (+0200) Subject: Added lsanime. X-Git-Url: http://git.dolda2000.com/gitweb/?a=commitdiff_plain;h=03826bab09bd9d735568aa91fba81b839acdbb12;p=utils.git Added lsanime. --- diff --git a/lsanime b/lsanime new file mode 100755 index 0000000..df34a64 --- /dev/null +++ b/lsanime @@ -0,0 +1,99 @@ +#!/usr/bin/perl + +use Getopt::Long; +use Term::ReadKey; + +GetOptions(\%options, 'k', 'i', 't'); + +if(@ARGV > 0) { + chdir($ARGV[0]); +} +while($dir = <*>) { + if(-d $dir) { + $fl = {}; + if(-r "$dir/nextep") { + open NE, "$dir/nextep" || die; + $ne = ""; + $ne += $_ while ; + close NE; + if($ne == 1) { + $fl->{"first"} = 1; + } else { + $fl->{"act"} = 1; + } + $dirs{$dir} = $ne; + if(-r "$dir/.autodl/curep" && -r "$dir/.autodl/rtinfo") { + open DE, "$dir/.autodl/curep" || die; + $de = ""; + $de += $_ while ; + close DE; + if($ne < $de) { + $fl->{"hasmore"} = 1; + } else { + $fl->{"nomore"} = 1; + } + } + } + if(-r "$dir/.flags") { + open FL, "$dir/.flags" || die; + while() { + chomp; + $fl->{$_} = 1; + } + close FL; + } + $dirs{$dir} = $fl; + } +} +if(! -t STDOUT) { + die "not on a tty"; +} +for (keys %dirs) { + $cns = $options{"k"} == $dirs{$_}->{"kaka"}; + # $cns = 0 if $dirs{$_}->{"notdone"} && !$options{"i"}; + if($cns) { + if($dirs{$_}->{"lp"}) { + $nc = 31; + } elsif($dirs{$_}->{"first"}) { + $nc = 32; + } elsif($dirs{$_}->{"hasmore"}) { + $nc = 36; + } elsif($dirs{$_}->{"nomore"}) { + $nc = 35; + } elsif($dirs{$_}->{"act"}) { + $nc = 33; + } else { + $nc = 34; + } + } else { + $nc = 34; + } + if($options{"t"} && ($nc == 34)) { + delete $dirs{$_}; + } else { + $dirs{$_}->{"color"} = $nc; + } +} +$cw = 0; +for $d (keys %dirs) { + $l = length $d; + $cw = $l if $l > $cw; +} +$cw += 2; +($w, $h) = GetTerminalSize; +$cols = int($w / $cw); +@sorted = sort keys %dirs; +$percol = int(@sorted / $cols) + 1; +for($i = 0; $i < $percol; $i++) { + for($o = 0, $x = 0; $o < $cols; $o++) { + $n = ($o * $percol) + $i; + last if $n >= @sorted; + print (" " x (($cw * $o) - $x)) if $x < $cw * $o; + $_ = $sorted[$n]; + $x = $cw * $o; + $nc = $dirs{$_}->{"color"}; + print "\e[${nc}m$_\e[39m"; + $x += length; + } + print "\n"; +}