aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Tom Willemse2022-05-26 23:32:52 -0700
committerGravatar Tom Willemse2022-05-26 23:32:52 -0700
commita3be7607212d481b1b261b33e00bcf1d13a6abe6 (patch)
tree8ad64f9c4c4d82bb1999c90391a56d930fa261b5
parentd344d290c4f9bae23467db3aa40df17521c725e3 (diff)
downloadcount-emails-a3be7607212d481b1b261b33e00bcf1d13a6abe6.tar.gz
count-emails-a3be7607212d481b1b261b33e00bcf1d13a6abe6.zip
Use notmuch if available to count unread emails
-rwxr-xr-xcount-emails24
1 files changed, 12 insertions, 12 deletions
diff --git a/count-emails b/count-emails
index 787d69d..4bb75c1 100755
--- a/count-emails
+++ b/count-emails
@@ -1,17 +1,17 @@
#!/usr/bin/env sh
# -*- mode: scheme; -*-
IFS=" "
-exec scsh -s "$0" "$@"
+exec scsh -o thread-fluids -s "$0" "$@"
!#
-(define mail-root (string-append (getenv "HOME") "/documents/mail"))
-
-(define unread-emails
- (run/sexp (pipe (find ,mail-root -type f -name "*:2,*" -and -not -name "*:2,*S*")
- (wc -l))))
-
-(define new-emails
- (run/sexp (pipe (find ,mail-root -type f -wholename "*/new/*")
- (wc -l))))
-
-(display (+ unread-emails new-emails))
+(if (exec-path-search "notmuch" (thread-fluid exec-path-list))
+ (display (length (run/sexp (notmuch search --output=files --format=sexp tag:unread))))
+ (begin
+ (let* ((mail-root (string-append (getenv "HOME") "/documents/mail"))
+ (unread-emails
+ (run/sexp (pipe (find ,mail-root -type f -name "*:2,*" -and -not -name "*:2,*S*")
+ (wc -l))))
+ (new-emails
+ (run/sexp (pipe (find ,mail-root -type f -wholename "*/new/*")
+ (wc -l)))))
+ (display (+ unread-emails new-emails)))))