So, if you're like me and like to have your IRC client (in this instance irssi) running on a server in a tmux
or screen
session to never miss out on the conversation, you might feel like you're missing some of the benefits of running a local IRC client.
In particular, I was missing local notifications when someone would highlight my nickname. I could of course use a bouncer, but hey! it's no fun running irssi
locally and having to close it for a reboot just as you've gotten it precisely the way you like it 🙂...
So, how does one solve this problem?
The final setup will look something like this,
You can replace terminal-notifier
with whatever notification program will work on your system. The rest is pretty much OS agnostic, except for the automatic startup of the script.
First off, I'm assuming you're running the fnotify plugin in irssi, and that you have setup private keys between you and the server. These are the only things you need to do server-side.
On your local setup you'll need,
sudo port install autossh
sudo port install terminal-notifier
orsudo gem install terminal-notifier
We use autossh
to keep our ssh connection from dropping, and killing the script (so you don't have to constantly restart it whenever you close the lid on your laptop).
To display the notifications, we use terminal-notifier
, which creates native notifications on OS X. You can change this out with whatever program your OS needs.
So, to the fun part. First off, create a file called something like irssi_notifier.sh
in a location you don't mind it being in forever, but can still remember (at least until the end of this article).
In this script, you'll need the following code. I'll explain what it does below (replace the two user@server instances with your details!),
#!/bin/bash
# Make sure we don't make a new autossh connection
if ! | ; then
;
fi;
# Avoid relaunching the notifier function if it's already running
if ! | ; then
fi;
irssi_notifier
function, we connect to the server with irssi
on, and read via tail from the fnotify file.terminal-notifier
to just activate our terminal upon click on the notification.autossh
.irssi_notifier
function, and start the notification service.In the last two calls, we check if the processes exist, and only call them if they don't. This avoids spamming a zillion autossh
connections etc.
If you just want to test it, you can just run the script (remember to chmod +x it) without the autossh
part (just comment it out). If you use autossh
, you'll need to kill the process if you relaunch the script, else it'll keep spawning more and more autossh
processes.
NOTE: This is specific for OS X, but I'm sure there are ways for other OSs
If you're lazy like me, you probably aren't satisfied quite yet. There is still the part about starting the script yourself whenever you boot up your system.
On OS X, this is quite simple (once you know how to do it, that is). We will use launchctl, which manages programs that launch upon startup.
To launch the script, you need to create a file called com.irssi.notifier.plist
in ~/Library/LaunchAgents/
. The contents will be,
Label
com.irssi.notifier
ProgramArguments
/absolute/path/to/irssi_notifier.sh
KeepAlive
The only thing you need to change is under ProgramArguments
, where you substitute /absolute/path/to/irssi_notifier.sh
with the actual path to the script file.
Finally, you need to do launchctl load ~/Library/LaunchAgents/com.irssi.notifier.plist
.
After this, you should be good to go! Now you can enjoy getting IRC highlights whenever you have a working connection.
Try and reboot, and check if it works :)
Q: Why not use mosh instead of autossh? The reason I didn't use mosh
to do what I accomplished with autossh
, is because of running into trouble executing commands directly after a connection initiation (mosh user@server 'echo 1'
fails instantly, to give an example).
That said, I do recommend using mosh instead of ssh normally, since it works excellent :).