checking for toots
The mastodon cli client toot is pretty nice for tootinβ. If I want to post something I can just toot post "some really unique thought" and BAM itβs out there on the internet forever. It even supports media β EG echo 'can I pipe stuff into toot?' | toot post -m $(shot) and I can put adhoc screenshots in there:
This is all well and good, but then Iβm blind to when replies to toots happen (and with FOMO, I end up checking more often than I have too). Luckily, the toot cli client has a way to check for notifications. Unluckily, the toot nofications donβt come through in a very structured way, and thereβs no way to get βunseenβ notifications, it just sends everything (or well, some last N notifications):
$ toot notifications
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
@friend@linuxrocks.online mentioned you in
@friend@linuxrocks.online 2020-04-28 16:22
@neeasade
Hidden windows as in minimized? I thought, bspwm doesn't have that...?
ID 104077129364588593 β² In reply to 104076791236950072
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
βοΈ Lazr βοΈ @lazr@mstdn.io reblogged your status
kitten mittens @neeasade 2020-04-28 14:56
bspwm breaks a little on with lots of hidden windows (see the smooshed boi in the gap)
Media:
https://mastodon.social/media/H7EiE9_nJzLtHDbPRxs
ID 104076791236950072
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
hazel :blobcatcomfy: @hazel@is.nota.live now follows you
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
...
Note: There is the ability to clear all notifications, but then you also lose upstream history β Iβd like to preserve that.
Rolling my own#
Alright, I need 2 things β a way to mark the current set of notifications as βseenβ and a way to check the content of βunseenβ notifications (I only care if mentions happen, not necessarily boots or favs). I need to delimit based on that weird separator.. at first I reached for grep and sed, but they donβt quite handle multiline iteration that well β awk has me covered though! After some searching I stumble upon the internal RS (record separator) variable. Since the value it takes is a regex, I can do the following to map over toots:
toot notifications | awk 'BEGIN { RS="\nβ+\n" }; {print $0}'
And with diff, I can check if anything has changed (provided I save the seen notifications output somewhere). First I isolate to just the new content, and then I count how many of the new notifications contain βmentioned youβ (I only have FOMO about conversation):
#!/usr/bin/env bash
# to save the 'seen' state (will mapped to a click on the panel):
# toot notifications >/tmp/toot-notifications.txt
count=0
if ! diff=$(diff <(toot notifications) <(cat /tmp/toot-notifications)); then
new_content=$(echo "$diff" | grep '^<' | sed 's/< //')
count=$(echo "$new_content" | awk 'BEGIN { RS="\nβ+\n" }; /mentioned you/{print "mentioned"}' | wc -l)
fi
echo "toot mentions: $count"
From there itβs a short trip to have a panel button, you just call the script!
With a click action to βMark toots as seenβ(just updating the temp file) and open up mastodon, Iβm all set for some distration free tootinβ without the FOMO of mentions.