Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Tehnix/6160437 to your computer and use it in GitHub Desktop.
Save Tehnix/6160437 to your computer and use it in GitHub Desktop.
Get local notification alerts from irssi on a remote server, and use autossh to keep the ssh connection alive after connection loss.

Local notification alerts from irssi on a remote server (and keep the ssh connection alive after connection loss)

First of all, thanks to prebenlm for making his walkthrough Irssi in Mac OS X Notification Center.

This is made with OS X in mind, but, should be easily transported over to other systems. Just use another notification system instead of the Apple Notification center and terminal-notifier (and you'll also have to workout the auto launch of the scripts yourself)...

Programs you'll need

  1. autossh
  2. terminal-notifier

Both are available via macports or brew...

I'm assuming irssi is already set up on a remote server with the fnotify plugin.

Set up autossh

Make an automator application (run as shell script) executing the following:

/opt/local/bin/autossh -M 0 -f -N -p 22 -g -c 3des -D 1080 user@server

A picture depicting this step: Automator shell script

Set up terminal-notifier

You need to have your server set up with a private key first.

Add the following function to your .bashrc/.zshrc at the bottom:

irssi_notifier() {
  (ssh user@server -o PermitLocalCommand=no \
    ": > .irssi/fnotify ; tail -f .irssi/fnotify " |  \
  while read heading message; do                      \
    url=`echo "${message}" | grep -Eo 'https?://[^ >]+' | head -1`; \
    if [ ! "$url" ]; then terminal-notifier -message "${message}" -title "${heading}" -activate com.googlecode.iterm2; \
    else terminal-notifier -message "${message}" -title "${heading}" -open "${url}"; \
    fi; \
  done)
}
  • Replace the user@server bit, with your server information.
  • Adjust the paths to fnotify
  • the -activate com.googlecode.iterm2 bit will activate iTerm2 open click. If you use the terminal, replace this with com.apple.Terminal.
  • It will open urls in your browser, if it's found one in the highlight.

then, create a script in a place you remember, called irssi_notify.sh, with the following (change to bash if you're using that)

#!/opt/local/bin/zsh
source ~/.zshrc; irssi_notifier;

Launch on startup

To make autossh launch on startup, simply add the .app file to login items.

To make the irssi_notifier.sh script launch on startup, navigate to ~/Library/LaunchAgents and a file called com.irssi.notifier.plist with the following content:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
  <key>Label</key>
  <string>com.irssi.notifier</string>
  <key>Program</key>
  <string>/User/username/Documents/irssi_notify.sh</string>
  <key>KeepAlive</key>
  <true/>
</dict>
</plist>

Where you replace username with your username (or, replace the path with whereever you stored irssi_notify.sh).

Lastly, run launchctl load ~/Library/LaunchAgents/com.irssi.notifier.plist to add it to the startup items.

Done!

Now you can enjoy getting IRC highlights whenever you have a working connection.

A side-note, 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, except for that specific usecase.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment