Skip to content

Instantly share code, notes, and snippets.

@niko
Last active August 7, 2019 21:43
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save niko/7816377 to your computer and use it in GitHub Desktop.
Save niko/7816377 to your computer and use it in GitHub Desktop.
i3wm & mutt: check mails, blink caps lock led, mark mail workspace as urgent.

This puzzle has 3 parts:

  • A i3wm config that opens mutt in a dedicated workspace. $mod+m will switch to this workspace and will launch mutt, if not already running. Actually it doesn't launch mutt, but…
  • a small wrapper script, which opens a named pipe and then starts mutt.
  • a checkmail script which uses mailcheck(1) to tara check mail. If new mail is available, it blinks the CAPS LOCK led (which I mapped to CTRL anyway) and marks the mutt workspace via a bell.

Additional configuration:

  • set your terminal to mark urgent bells. In Termite the setting is "urgent_on_bell = true".
  • adopt you ~/.mailcheckrc to include paths to your mailboxes. In the simplest case it contains just the line "$(HOME)/Maildir/INBOX"

Place the checkmail script in ~/bin/checkmail and run in background on login.

#!/bin/bash
RATE=60 # how often to check mails
while true; do
UNREAD=$(mailcheck -c | cut -f3 -d ' ')
if [ "x$UNREAD" != "x" ]; then
if [ -p /tmp/mailnotify ]; then
echo -e "\a" > /tmp/mailnotify
fi
xset led named "Caps Lock"
# blink $UNREAD times, then sleep 1; repeat $RATE times
for ((i = 1; i <= $RATE; i++)); do
for ((j = 1; j <= $UNREAD; j++)); do
xset -led named "Caps Lock"
sleep 0.1
xset led named "Caps Lock"
sleep 0.1
done
sleep 1
done
else
# no unread? just wait $RATE
echo 'on mail'
xset -led named "Caps Lock"
sleep $RATE
fi
done
bindsym $mod+m workspace mail; exec --no-startup-id "flock -xn /tmp/mutt.lock -c 'termite -e ~/bin/mutt_with_notify'"
#!/bin/bash
if [ ! -p /tmp/mailnotify ]; then
mkfifo /tmp/mailnotify
fi
while true; do cat < /tmp/mailnotify; done &
mutt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment