I’m usually on IRC, but I don’t often notice incoming pings until after the fact. I had to both write, and modify various scripts to get what I wanted, but now it’s all done, and you can benefit from my hacking by following along…
Laptop -> Gnome-Terminal -> SSH -> Screen -> Irssi
This way, I’m connected to IRC, even when my laptop isn’t. I run irssi in a screen session on an SSH server that I manage, and I use gnome-terminal on my laptop. If you don’t understand this setup, then you’ll need to get more comfortable with these tools first.
The first trick is getting irssi to store notifications in a uniform way. To do this, I modified an irssi script called fnotify. My changed version is available here. Installation is easy:
# on your ssh server: cd /tmp; wget https://dl.dropboxusercontent.com/u/48553683/irssi/fnotify.pl cp /tmp/fnotify.pl ~/.irssi/scripts/ # in irssi: irssi> /load perl irssi> /script load fnotify
When someone sends you a direct message, or highlights your nick on IRC, this script will append a line to the ~/.irssi/fnotify file on the SSH server.
On your local machine, we need a script to tail the fnotify file. This was surprisingly hard to get right. The fruit of my labour is available here. You’ll want to copy this script to your local ~/bin/ directory. I’ve named this script irssi-fnotify.sh. This script watches the remote fnotify file, and runs notify-send and paplay locally to notify you of any incoming messages, each time one comes in.
We want the irssi-fnotify.sh script to run automatically when we connect to our SSH server. To do this, add the following lines to your ~/.ssh/config file:
# home Host home HostName home.example.com PermitLocalCommand yes LocalCommand ~/bin/irssi-fnotify.sh --start %r@%h
You might also want to have other directives listed here as well, but that is outside the scope of this article. Now each time you run:
The irssi-fnotify.sh command will automatically run.
I’ve left out some important details:
- The LocalCommand that you use, must return before ssh will continue. As a result, it daemonizes itself into the background when you invoke it with –start.
- My irssi-fnotify.sh program watches the parent ssh $PID. When it exits, it will run a cleanup routine to purge old notifications from the fnotify file. This requires a brief SSH connection back to the server. This is a useful feature!
- You may wish to modify irssi-fnotify.sh to paplay a different alert sound, or to avoid making noise entirely. The choice is yours.
- When irssi-fnotify.sh runs, it will tail the fnotify file over ssh. If there are “unread” messages, tail will try to “download” up to ten. You can edit this behaviour in irssi-fnotify.sh if you want a larger initial backlog.
- The irssi-notify.sh script doesn’t attempt to prevent flooding, nor does it filter weird characters from incoming messages. You may want to add this yourself, and or /kb users who cause you to need these features.
Here’s a little screenshot (with shameless plug) of the result in action:
Here’s an example of how this helps me to be more responsive in channel:
I hope you found this useful.