diff options
author | Karel Kočí <cynerd@email.cz> | 2017-04-03 20:44:11 +0200 |
---|---|---|
committer | Karel Kočí <cynerd@email.cz> | 2017-04-03 20:44:11 +0200 |
commit | 5632e0be34c7a07227543d3b44c3be7a1387613e (patch) | |
tree | 19f647dedb6f565c0d4cd3c738f174e4e2796ef1 | |
parent | 81836945a63f726033fb6550755e2c9dbf1a1f83 (diff) | |
download | myconfigs-5632e0be34c7a07227543d3b44c3be7a1387613e.tar.gz myconfigs-5632e0be34c7a07227543d3b44c3be7a1387613e.tar.bz2 myconfigs-5632e0be34c7a07227543d3b44c3be7a1387613e.zip |
Update email-unread script
-rwxr-xr-x | config/i3blocks/scripts/email | 3 | ||||
-rwxr-xr-x | install | 1 | ||||
-rwxr-xr-x | local/bin/email-unread | 67 |
3 files changed, 34 insertions, 37 deletions
diff --git a/config/i3blocks/scripts/email b/config/i3blocks/scripts/email index 138deb8..3c1fb1f 100755 --- a/config/i3blocks/scripts/email +++ b/config/i3blocks/scripts/email @@ -1,5 +1,4 @@ #!/bin/bash - -email-unread -s | tr "\n" " " | sed 's/[ ]*$/\n/' +echo $(email-unread -s | tr "\n" " ") echo echo "#ffff00" @@ -58,6 +58,7 @@ fi read -p "Install email synchronization? (Y/n) " if [[ $REPLY =~ ^[Yy]?$ ]]; then + inst local/bin/email-unread ~/.local/bin/email-unread inst_email_sync # Contains: # inst local/sbin/syncemail ~/.local/sbin/ diff --git a/local/bin/email-unread b/local/bin/email-unread index f9e3aa9..3956f3b 100755 --- a/local/bin/email-unread +++ b/local/bin/email-unread @@ -1,37 +1,34 @@ -#!/bin/bash -EMAIL=~/.mail -IGNORE="(Spam|trash|Important)" +#!/bin/perl +use strict; +use warnings; +use File::Find; -if [ "$1" == "-s" ]; then - V=n -else - V=y -fi +use constant EMAIL => glob("~/.mail"); +my $IGNORE = "(Spam|trash|Important)"; -for account in $(ls "$EMAIL"); do - if ! cd $EMAIL/$account; then continue; fi - COUNT="0" - COUNT=$(find . -name new -type d -print0 | - while read -d $'\0' folder; do - if [ -n "`echo $folder | grep -E $IGNORE`" ]; then - continue - fi - directory=$(echo $folder | sed 's/^\.\///' | sed 's/\/new$//') - count=$(ls "$folder" | wc -l) - if [ "$count" -gt "0" ]; then - if [ $V == 'y' ]; then - echo "$account/$directory: $count" - else - let 'COUNT = COUNT + count' - echo $COUNT - fi - fi - done | tail -1) - if [ -n "$COUNT" ]; then - if [ $V == "n" ]; then - echo "$account:$COUNT" - else - echo $COUNT - fi - fi -done +my $V = (shift || "") eq "-s"; + +opendir(EDIR, EMAIL) or die $!; +while (readdir EDIR) { + next if /^\./ or not (-d EMAIL."/$_"); + our $count = 0; + + sub new_dir { + my $path = substr $File::Find::name, 1 + length EMAIL; + $path =~ s/\/new$//; + return if $_ ne "new" or $path =~ /$IGNORE/; + #print "ok: $path\n"; + my $cnt = 0; + opendir(NDIR, "$File::Find::name") or die $!; + while (readdir NDIR) { + $cnt += 1 unless /^\./; + } + closedir(NDIR); + print "$path: $cnt\n" if not $V and $cnt > 0; + $count += $cnt; + } + find(\&new_dir, EMAIL."/$_"); + + print "$_: $count\n" if $V and $count > 0; +} +closedir(EDIR); |