55 lines
1.4 KiB
Bash
Executable file
55 lines
1.4 KiB
Bash
Executable file
#!/bin/env bash
|
|
|
|
# named pipe for receiving refresh events
|
|
# from mail sync script
|
|
PIPE="/tmp/email_refresh_pipe"
|
|
# COUNT="/tmp/email_count"
|
|
|
|
# if [ -f /tmp/email_indicator_lock ]; then
|
|
# exit 1
|
|
# fi
|
|
# Create pipe if doesn't exist
|
|
[[ -p "$PIPE" ]] || mkfifo "$PIPE" && touch /tmp/email_indicator_lock
|
|
|
|
# if [ ! -e "$COUNT" ]; then
|
|
# echo "0" > "$COUNT"
|
|
# fi
|
|
|
|
# mailboxes to monitor
|
|
# MAILBOXES=("personal" "school")
|
|
# Get unread counts and format for waybar
|
|
get_unread_counts() {
|
|
# for mailbox in "${MAILBOXES[@]}"; do
|
|
pcount=$(notmuch count --output=messages "tag:unread and path:personal/**")
|
|
scount=$(notmuch count --output=messages "tag:unread and path:school/**")
|
|
# printf "%s: %s " "$mailbox" "$count"
|
|
# done
|
|
# we print a newline to let waybar know to display
|
|
# what we just printed
|
|
if [ "$pcount" = 0 ] && [ "$scount" = 0 ] ; then
|
|
echo ""
|
|
else
|
|
echo "p: $pcount s: $scount |"
|
|
fi
|
|
}
|
|
|
|
# run once for initial output
|
|
# echo "mail init |"
|
|
# begin event loop
|
|
while true; do
|
|
# cat blocks until data comes through pipe
|
|
# redirecting to null b.c. we don't want the
|
|
# pipe's contents to be printed to stdout
|
|
PAYLOAD=$(cat /tmp/email_refresh_pipe)
|
|
if [ "$PAYLOAD" == "new" ]; then
|
|
echo "m* |"
|
|
# count=$(cat "$COUNT")
|
|
# ((count++))
|
|
# echo "$count" > "$COUNT"
|
|
# echo "new: $(cat "$COUNT") |"
|
|
# elif [ "$PAYLOAD" == "reset" ]; then
|
|
# "0" > "$COUNT"
|
|
else
|
|
get_unread_counts
|
|
fi
|
|
done
|