54 lines
918 B
Bash
Executable file
54 lines
918 B
Bash
Executable file
#!/bin/sh
|
|
set -e
|
|
|
|
if test -z "$SWAYSOCK" && pidof gnome-shell &> /dev/null
|
|
then
|
|
exit 0
|
|
fi
|
|
|
|
test -z "$XDG_RUNTIME_DIR" &&
|
|
export XDG_RUNTIME_DIR=/run/user/$(id -u)
|
|
|
|
die() {
|
|
test "$?" = 0 ||
|
|
notify-send "Failed to sync mail" "try unlocking your gpg key"
|
|
}
|
|
trap die EXIT
|
|
|
|
getnew() {
|
|
pushd "$HOME/.local/share/mail/" >/dev/null
|
|
|
|
find */INBOX*/new -type f |
|
|
sed -E '/Duolingo|LBRY/d' |
|
|
wc -l
|
|
|
|
popd >/dev/null
|
|
}
|
|
|
|
OLD=$(getnew)
|
|
|
|
if test "$1" = "update" && ! pidof mbsync; then
|
|
if ! ping -c3 {{@@ mail.personal.mail @@}} &> /dev/null
|
|
then
|
|
exit 0
|
|
fi
|
|
mbsync -a ||
|
|
mbsync -a ||
|
|
mbsync -a
|
|
fi
|
|
|
|
NEW=$(getnew)
|
|
|
|
if test "$NEW" -gt "$OLD"; then
|
|
notify-send " New E-Mails!"
|
|
fi
|
|
|
|
echo $NEW | sed 's/^0$//'
|
|
|
|
caller=$(ps -o comm= $PPID)
|
|
if test "$caller" != "waybar"; then
|
|
pidof waybar >/dev/null &&
|
|
pkill -SIGRTMIN+4 waybar
|
|
fi
|
|
|
|
# vim:ft=sh
|