Irssi and Screen and Growl, oh my!

Over the last few weeks, I’ve been getting accustomed to my new job here at Mozilla. Something that is used very extensively here is IRC chat. Since the last time I used IRC for work was about two jobs ago, back when I was solely working on linux desktops, I didn’t really have much experience with the various IRC clients available for Mac. Colloquy is pretty nice, but I couldn’t figure out how to make it store my channel passwords, such that the client will automatically reconnect after waking the computer from sleep. X-Chat Aqua was also pretty nice and had some good features as well as being very customizable. I would recommend this to anyone that wants to really tweak their IRC experience.

However, one feature that neither client offered is, of course, staying connected to the IRC server when the computer is asleep. It is quite useful for me to be able to log into the IRC channels that my colleagues are on and be able to scroll back a ways to see what the current conversation is about, or to see if I missed anything that is important to me. The obvious solution here is to use an IRC client running on a remote machine that is always running. Most people I’ve talked to use the Irssi running in a screen session on a shell server somewhere. This is a perfect solution to the stated problem.

Using this method to connect to the IRC does bring up one whole new problem. Since I am in anywhere from 7 to 10 different IRC channels at a time and have work to do that doesn’t involve watching all channels all the time, I’ve relied on Growl notifications to alert me whenever someone mentions my nick. This is one feature that most people have to give up on in order to stay connected using Irssi in a Screen session. Well, I did some research and found a couple of pages on the internet that provided very useful information to make possible using Irssi in a screen session on a remote server and still get Growl notifications anytime your nick is mentioned! Here is how to do it:

First of all, I won’t go into setting up Irssi or Screen. There is more than enough documentation on the web to help with doing that. Also, I don’t want to take credit for figuring out how to do this. Most of the information came from this page.

First step:
Download this script, unzip it and place it in your ~/.irssi/scripts/autorun/ folder (create this directory if it doesn’t exist yet).

Second step:
Make sure your SSH public key is on the remote server where you will be running your irssi instance.

Third step:
Create a script on your local computer. I named it “growl_irc.sh” and placed it in my ~/bin/ directory, which I have added to my PATH variable.


#!/bin/bash
# Kill all current fnotify sessions
ps | awk '{if($0 ~ /fnotify/ && $1 ~ /[0-9]+/ && $4 !~ /awk/) print $1}' |
while read id; do
kill $id
done
# SSH to host, clear file and listen for notifications
(ssh username@hostname -o PermitLocalCommand=no \
"> .irssi/fnotify; tail -f .irssi/fnotify" |
while read heading message; do
growlnotify -t "${heading}" -m "${message}";
done)&

Fourth Step:
Download and install growlnotify. It is in the DMG in a directory called Extras that you can download from http://growl.info/

Fifth Step:
Write a simple script, which opens an SSH session to the remote host and also starts the growl_irc.sh script. I call it “irc” and put it in my ~/bin/ directory:


#!/bin/bash
~/bin/growl_irc.sh
ssh user@hostname

Sixth Step:
On the remote server, I wrote another little wrapper script to resume the screen session. It just has one line:

screen -raAd

This can also be called “irc” or this line could be added to the .bash_profile file, if that is all the remote server will be used for.

So now my workflow is as follows: Open a terminal, type irc, once logged into the remote server, type irc again and I have my Irssi up and running with working growl notifications. Enjoy!

Extra tips:
Since I don’t want my irssi window to get lost among all the other terminal windows I have open, I use Terminal.app for regular terminal work and iTerm for Irssi. This way I can have default window sizes and colors for Irssi be different than for other terminal stuff.

You can configure the growlnotify Application in the Growl Preference Pane to make changes to how long the notification stays on screen, etc.

If you read the manpage for growlnotify, you can find ways to tweak the notification’s icon, etc.

Look at the scripts available on http://www.irssi.org/scripts to find how to change the appearance of Irssi, i.e. to get colored nicks and a list of active nicks in a channel on the sidebar, reminiscent of X-Chat or other GUI clients.

18 Comments

randMarch 27th, 2010 at 04:47

Great post – more like this!
I might adapt the script to notify me if there is *any* activity in a channel, not just activity addressed to me.

FredMarch 27th, 2010 at 16:30

Good stuff! Another way to keep logged in to IRC when your computer goes to sleep is an IRC bouncer, which essentially works like a proxy server, except for IRC connections.

teKApril 13th, 2010 at 19:25

I am surprised you didn’t discover Quassel — runs as a daemon on a machine and you can connect clients to it from any of the major os’. Saves passwords, supports multiple networks, identification, all the fun stuff. quassel-irc.org

jabbaApril 13th, 2010 at 20:43

teK: thanks for the tip! That does look quite interesting. Part of the problem was that the shell server I’ve been using only had SSH port open for me and I didn’t have root on the box. I’ve since set up my own “always-on” box for this, so I’ll definitely take a look at running Quassel on it.

ChrisApril 18th, 2010 at 18:33

I’m using ZNC for my setup, even have bitlbee running so I can do all my instant messaging through it as well. The thing that really sold me is with bitlbee-otr + znc w/ ssl I now have secure IM with push notifications to my iPhone. I am using Colloquy on my Mac and my iPhone but want to move to irssi for Mac. Thanks for the help with Growl.

http://www.bitlbee.org
http://sourceforge.net/projects/znc/

jabbaApril 18th, 2010 at 21:12

@Chris: Thanks for the info bitlbee and znc, I think I might try those out as well.

If you are going to be running irssi locally on your mac (since you are using ZNC), then the growl stuff will still work, but you can modify the script to just read the fnotify file directly rather than having to open up an SSH connection.

JørgenJune 2nd, 2010 at 18:35

Hey, just a tip. You say:

“So now my workflow is as follows: Open a terminal, type irc, once logged into the remote server, type irc again and I have my Irssi up and running with working growl notifications. Enjoy!”

If you change your local “irc” script to say “ssh -t user@hostname irc” instead of “ssh user@hostname
“, it will automatically start irc at the remote end for you. :)

Great article!

Bjarte Stien KarlsenNovember 12th, 2010 at 08:39

I had to use ~/.irssi/fnotify as the path but other then that it worked for me.

JacobNovember 19th, 2010 at 06:27

Awesome. Thank’s mate. Just got a mac and this made it infinitely more enjoyable to use.

Lukas BlakkFebruary 3rd, 2011 at 18:23

This is awesome and the only tweak I had to do was /script load autorun/fnotify.pl since my irssi was already running.

Antonio TouriñoMay 8th, 2011 at 20:31

Thanks for the walkthrough. Just the thing I needed.

teewuaneJune 1st, 2011 at 19:19

hmm. i use zshell and i’m trying to think of a way to make this work. Can I have zshell run a bash command?

jabbaJune 1st, 2011 at 20:43

Sure. You could probably change the #!/bin/bash to #!/bin/sh or whatever you want. I don’t think the script is doing anything bash-specific. I just happen to default to #!/bin/bash for my scripts because I know it is always going to be there and be relatively the same on all distros.

Persistent IRC | Threadbox.netAugust 6th, 2011 at 06:16

[...] notifications for mentions/PM’s! I just actually set it up on my Mac with Growl according to this article. I did it once under linux, [...]

zibvousAugust 8th, 2011 at 11:43

Call me old school but i’m just using the standard notification. name notified => highlight + beep
=> beep forwarded to my console
=> i hear beep

(alternative: sometimes i use the visual beep which just flashes the window – or could actually use growl if i had a mac and wanted that)

its much more simple and just as efficient imo.

For messages sent when i’m offline, i just read the highlight log when i cannot (spam of growl would sucks anyway)

jabbaAugust 8th, 2011 at 13:04

Yeah, that works too. My problem is that an audible beep drives me crazy and a visual beep doesn’t help, since the whole point is that I’m not watching irc all the time, as it’s usually on my secondary monitor or out of the way somehow.

Meanwhile I stopped using screen and instead run irssi on my local box connected to a znc server, so I’ve modified the script here to not deal with all the ssh stuff and just tail the fnotify file locally. I’m pretty happy with it still.

BenApril 17th, 2012 at 23:36

Excellent info, thank you! Naturally I could not resist tinkering ;)

I added this:

Host mychathost
Hostname mychathost.dayjob.com
PermitLocalCommand yes
LocalCommand ~/bin/growl_irc.sh

to ~/.ssh/config. Now when I ‘ssh mychathost’ it automagically starts up, with one less little script running :) Also, I modified the growl_irc.sh script to use -q in its ssh so as to not show me issue.net all the time on STDERR.

If you had multiple irssi hosts, you could even use the `%h’ variable to pass the hostname to growl_irc, make a $0-%h pidfile, not start if the pidfile exists and is linked to a pid, and make the growlnotify use %h as the subject… Voila, multihost irssi growlage.

[...] SOMEONE is doing irssi in screen and wants growl notifications”. As ridiculous as it sounds, someone was. I took their approach, briefly outlined below, and customized it a little to make me happy. For [...]

Leave a comment

Your comment