I’ve been wanting a (good) way to get notifications from irssi in the foreground for a while now. Let’s say, oh, two years.
My irssi setup is fairly standard: irssi running in screen on a remote server. There’s a few ways people have come up to run around this:
- Run the SSH session with X forwarding and use notify-send to pop up new messages
- Run a second SSH session to access a fifo of new messages and pop them up as they come
- Move your windows around so that you can always see the status bar at the bottom of irssi
The first two are, if you’re not careful, prone to attack — the most basic bash script to send messages to notify-send can easily run commands to remove files, etc., if you don’t escape quotes. The third one is impossible if you use a tiling window manager like awesome.
Since I use awesome, it’s really stupidly easy to create a widget in the status bar at the top. Add something along the lines of this to your rc.lua:
myirssistatus = widget({ type = "textbox" })
Add it to the wibox:
-- Create the wibox
mywibox[s] = awful.wibox({ position = "top", screen = s })
-- Add widgets to the wibox - order matters
mywibox[s].widgets = {
{
mylauncher,
mytaglist[s],
mypromptbox[s],
layout = awful.widget.layout.horizontal.leftright
},
mylayoutbox[s],
mytextclock,
myirssistatus,
s == 1 and mysystray or nil,
mytasklist[s],
layout = awful.widget.layout.horizontal.rightleft
}
And it’s there. Of course, it’s empty. That’s where the combination of an irssi script and a bash script come into play.
The irssi script activity_file.pl simply spits out a CSV file listing the IRC channels your in, in the following format:
num,act,channel,network
num is the channel number, act is an integer representing channel activity (0 for none, 1 for crap, 2 for messages, and 3 for hilights), channel is, well, the channel (e.g., #fedora-devel) and network is the name of the network that channel is related to (see /help network). Everything you need.
The script spits that data out to ~/.irssi/activity_file, and I have it symlinked into somewhere in ~/public_html (not the most secure, but it’s not like there’s any personal information in my channel list), and this bash script picks it up and runs with it:
#!/bin/bash
trap cleanup 2
cleanup()
{
echo "myirssistatus.text = ''" | awesome-client
exit 0
}
while true; do
DATA=""
for line in $(curl -s URL_GOES_HERE); do
win=$(echo $line | cut -d ',' -f 1)
sta=$(echo $line | cut -d ',' -f 2)
if [ "$sta" = "1" ]; then
DATA="$DATA $win"
elif [ "$sta" = "2" ]; then
DATA="$DATA $win"
elif [ "$sta" = "3" ]; then
DATA="$DATA $win"
fi
done
if [ "$DATA" ]; then
DATA="$DATA "
fi
echo "myirssistatus.text = \"$DATA\"" | awesome-client
sleep 5
done
The key there is when it pipes data into awesome-client. That’s really frickin’ neato.
So anyway. Is it a hack? Yes. Is it pretty? No. Does it work for me? Hell yeah. :)




