summaryrefslogtreecommitdiff
path: root/notmuch-links
blob: e46ddb2bd592b8af0d567c5ce6aa57d38c862728 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!@zsh@/bin/zsh

set -xe

function notmuch {
    NOTMUCH_INSTANCE=${NOTMUCH_INSTANCE:-rss} @notmuchssh@/bin/notmuch-ssh ${@}
}

function browser {
    ${BROWSER:-firefox} ${@}
}

maxCount=0
if [[ -n "$1" && "$1" == <-> ]]; then
    maxCount="$1"
fi

count=0
for thread (${(z)$(notmuch search --sort=oldest-first 'tag:inbox AND is:link AND is:unread AND NOT (is:killed or tag:later)' | @coreutils@/bin/tee >(cat >&2) | @gawk@/bin/awk '{ print $1; }')}); do
    url=$(notmuch show --format=mbox $thread | @gnused@/bin/sed -r '/^X-RSS-URL: /!d; s/^X-RSS-URL: (.*)$/\1/')
    count=$((count + 1))

    if [[ -n "${url}" ]]; then
      browser ${url} && notmuch tag -unread -inbox -- $thread
    fi

    if [[ ${maxCount} -gt 0 && ${count} -ge ${maxCount} ]]; then
        exit 0
    fi
done