#!/usr/bin/env bash
# ChkMail v0.3
# Written by jebug29
# 05 Sep 2018
# Add to your .profile to run when logging in

num_new=$(( $(mail -H 2>&1 | grep "^.N" | wc -l) ))
num_unr=$(( $(mail -H 2>&1 | grep "^.U" | wc -l) ))

num_emails=$(( num_new + num_unr  ))
s=""

if [ "$num_emails" -gt 1 ];then
	s="s"
fi

if [ "$num_new" -gt 0 ];then new="$num_new new"; fi
if [ "$num_unr" -gt 0 ];then unread="$num_unr unread"; fi
if [[ "$num_new" -gt 0 && "$num_unr" -gt 0 ]];then comma=", "; fi

if [ "$num_emails" -gt 0 ];then
	echo "You've got mail! ($new$comma$unread)"
else
	echo "No letter in the mail today, no message from my love."
fi
