-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathlm
executable file
·67 lines (54 loc) · 1.79 KB
/
lm
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
#!/Users/rjbs/perl5/perlbrew/perls/16.1/bin/perl
use 5.16.0;
use lib '/Users/rjbs/.perlbrew/libs/16.1@std/lib/perl5/';
use warnings;
use File::Find::Rule;
use List::AllUtils 'minmax';
use Term::ANSIColor;
use Time::Duration;
my $ROOT = "$ENV{HOME}/Maildir";
my @dirs = File::Find::Rule->directory
->maxdepth(1)
->exec(sub { -d "$_/new" })
->in($ROOT);
my $read = qr/,\w*S\w*\z/a;
my $flagged = qr/,\w*F\w*\z/a;
my %total;
for my $dir (sort @dirs) {
next if $dir =~ /spam.\d{4}/;
my @files = File::Find::Rule
->file
->maxdepth(2)
->exec(sub { $_[2] =~ m{/(?:new|cur)/} })
->or(
File::Find::Rule->not(File::Find::Rule->name($read)),
File::Find::Rule->name($flagged)
)
->in($dir);
next unless @files;
my $unread = grep {; $_ !~ $read } @files;
my $flagged = grep {; $_ =~ $flagged } @files;
$total{unread} += $unread;
$total{flagged} += $flagged;
my ($latest, $oldest) = minmax map {; $^T - (stat)[9] } @files;
$dir =~ s{\Q$ROOT\E(?:/(?:\.)?)?}{/INBOX/};
$dir =~ tr|.|/|;
$dir = '/INBOX' if $dir eq '/INBOX/INBOX' or $dir eq '/INBOX/';
printf "%-30s : %4u : %4u : %s%4s%s : %s%4s%s\n",
$dir,
$unread,
$flagged,
color( $latest < 900 ? 'bold green'
: $latest < 3600 ? 'bold yellow'
: 'reset'),
concise(duration($latest, 1)),
color('reset'),
color( $oldest < 900 ? 'bold green'
: $oldest < 3600 ? 'bold yellow'
: 'reset'),
concise(duration($oldest, 1)),
color('reset');
}
(grep {$_} values %total)
? (printf "%30s : %4u : %4u\n", 'total', $total{unread}, $total{flagged})
: (print "no new mail\n");