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