1
0
Fork 0
dotfiles/screen/mail

66 lines
1.9 KiB
Bash
Executable File

#!/bin/sh
#
# Unread E-mail screen status indicator
#
# Copyright (C) 2013 Mike Gerwitz
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# Unread e-mails will be displayed in the following format:
# [X X X unread!X]
#
# This utility uses fetchmail in order to check for new messages. Please
# configure your ~/.fetchmailrc file appropriately.
##
pidfile=~/.screen/.mail.pid
curpid="$( cat "$pidfile" )"
# kill any existing instances and replace (to ensure that code changes take
# effect)
[ "$curpid" ] && kill "$curpid"
echo "$$" > "$pidfile"
# this will be displayed until the first time the mail is received
echo "\005{+ mw}(...)\005{-}"
# continue looping while parent (screen) process is still running
parent="$PPID"
while [ "$( ps | grep $parent)" ]; do
fetchmail -t1 -c 2>/dev/null \
| sed 's/^\([0-9]\+\).*(\([0-9]\+\) seen).*$/\1 \2/' \
| awk '
BEGIN {
count=0
total=0
printf "%s", "\005{+ mw}[\005{+b}"
}
{
total = ( $1 - $2 )
count += $1
printf "%d ", total
}
END {
printf "%s", "\005{-}unread]\005{-}"
if ( count > 100 )
printf "%s%d%s", "\005{+ my}!", count, "\005{-}"
printf "\n"
}'
sleep 30
done