aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/.local/bin/mailnotify.sh
blob: 0c22e57b3c8f29cf094d7cf79b300aa756aab418 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
#!/usr/bin/env bash

mail=${HOME}/.mail/imperial/Inbox/new

inotifywait -m ${mail} | while read line; do
  if [[ $line =~ .*MOVED_TO ]] || [[ $line =~ .*CREATE ]]; then
    filename=$(echo "$line" | sed -E 's/[[:space:]]+((MOVED_TO)|(CREATE))[[:space:]]+//')
    subject=$(grep '^Subject:' $filename | sed -E 's/^Subject:[[:space:]]+//')
    from=$(grep '^From:' $filename | sed -E 's/^From:[[:space:]]+//')
    dunstify -i mail-unread "$from
$subject" "" &
  fi
done