helm/os/arch/.config/panel/lemons/mail

46 lines
901 B
Plaintext
Raw Normal View History

2016-11-02 16:58:47 -07:00
#!/usr/bin/env bash
set -e
CWD=$(dirname $0)
if [[ ! -f ~/.private/config/email ]]; then
>&2 echo "Couldn't load account settings"
exit 1
fi
. ~/.private/config/email
. $CWD/../panel-config
2016-11-02 16:58:47 -07:00
2016-11-06 16:40:02 -08:00
ICON_MAIL=""
get_mail() {
local feed=$(curl -u "$1:$2" --silent https://mail.google.com/mail/feed/atom)
if [[ "${feed//\<fullcount\>/}" != "$feed" ]]; then
echo "$feed" | grep -o "<entry>" | wc -l
else
>&2 echo "mail.sh: error with $1"
2016-11-06 16:40:02 -08:00
ERROR=!
echo 0
fi
}
2016-11-02 16:58:47 -07:00
a=$(get_mail "${MAIL1_USER}" "${MAIL1_PASS}")
b=$(get_mail "${MAIL2_USER}" "${MAIL2_PASS}")
c=$(get_mail "${MAIL3_USER}" "${MAIL3_PASS}")
2016-11-06 16:40:02 -08:00
num=$(( $a + $b + $c ))
icon="${ICON_MAIL}"
color="${COLOR_FG}"
case $num in
2016-11-06 16:40:02 -08:00
[1-9]*)
icon="$icon$num"
;;
0) color="${COLOR_DIM}"
;;
esac
[[ $ERROR ]] && color=${COLOR_1}
2016-11-06 16:40:02 -08:00
echo "M%{F$color}$icon%{F-}"
# vim:set ft=sh: