Skip to content

Commit e37b6d9

Browse files
andrewsancheztresni
authored andcommittedNov 13, 2017
Email checker for mail indexed with mu (matryer#905)
* Email checker for mail indexed with mu * Use bash instead of sh * Include image url and update documentation * Address shellcheck errors * Tidy up by storing parts of mu commands in variables * Conditional to display information only when unread mails > 0 * Store results of parenthetical statements instead of results of echo I was getting the wrong value for unread_total due to how wc -l was evaluating its input. This captures the correct value.
1 parent d34bffe commit e37b6d9

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed
 

‎Email/mu-email-checker.sh

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/bin/bash
2+
3+
# <bitbar.title>Mu Email Checker</bitbar.title>
4+
# <bitbar.version>v1.0.1</bitbar.version>
5+
# <bitbar.author>Andrew Sanchez</bitbar.author>
6+
# <bitbar.author.github>andrewsanchez</bitbar.author.github>
7+
# <bitbar.desc>Displays results of basic mu find commands</bitbar.desc>
8+
# <bitbar.image>http://i67.tinypic.com/104pa1w.png</bitbar.image>
9+
10+
# Count total number of emails in inbox, unread mail and drafts indexed with mu
11+
# Also includes the output for unread emails in the drop down menu
12+
# Based on a blog post by Ben Maughan at the excellent pragmaticemacs.com
13+
# http://pragmaticemacs.com/emacs/an-unobtrusive-email-monitor-for-mu4e-on-the-mac/
14+
# See related post to include mails in outbox using postfix
15+
# http://pragmaticemacs.com/emacs/using-postfix-instead-of-smtpmail-to-send-email-in-mu4e/
16+
17+
mu="/usr/local/bin/mu"
18+
19+
# mu find patterns
20+
pinbox="maildir:/INBOX"
21+
punread="$pinbox AND flag:unread"
22+
pdrafts="maildir:/drafts"
23+
24+
# Total mail in inbox
25+
total="$("$mu" find "$pinbox" | wc -l)"
26+
27+
# Unread mails in inbox
28+
unread="$("$mu" find "$punread" 2> /dev/null)"
29+
unread_total="$("$mu" find "$punread" 2> /dev/null | wc -l)"
30+
31+
# Drafts
32+
drafts="$("$mu" find "$pdrafts" | wc -l)"
33+
34+
if [ "$unread_total" -gt 0 ]
35+
then
36+
printf "📪 %i/%i/%i\n" "$unread_total" "$total" "$drafts"
37+
echo ---
38+
echo "$unread"
39+
fi

0 commit comments

Comments
 (0)
Please sign in to comment.