Skip to content

Instantly share code, notes, and snippets.

@dyoder
Forked from matthutchinson/fnotify.pl
Last active December 12, 2015 04:48
Show Gist options
  • Save dyoder/4716950 to your computer and use it in GitHub Desktop.
Save dyoder/4716950 to your computer and use it in GitHub Desktop.
Instructions and scripts for setting Up IRSSI so that it does native Apple notifications.
  1. Place the ssh-config file in ~/.ssh/config
  2. Place the irc-notify.sh file in ~/bin/irc_notify.sh
  3. Place the fnotify.pl file on the remote server within ~/.irssi/scripts
  4. Link the fnotify.pl script to ~/.irssi/scripts/autorun/fnotify.pl
  5. Install terminal-notifier (link?)
  6. SSH into the remote box: ssh personal -i .ssh/personal.pem (or whatever your keyfile is named).
  7. From there, run a tmux session and then run irssi.

When you login to the remote box (where you'll be running irssi), the SSH config will tell SSH to first run the irc-notify.sh script, which will clear the fnotify file and, in effect, pipe the tail of the fnotify file to your local terminal-notifier program. (It will first kill any such commands that are already running.)

When you start up irssi on the remote server, it will, in turn, run the fnotify.pl script, which will check for highlighted messages in IRC (i.e. referencing your nick, or whatever you have set up for highlighting), and then write those lines to the fnotify file.

Since you now have a process piping that file to terminal-notifier on your local box, you'll get notifications any time a message is highlighted. If the pipe dies for some reason (typically, I suppose, because the SSH session that's tailing the fnotify file dies), you'll have to SSH in again, but you don't usually need to start another irssi session.

# todo: grap topic changes
use strict;
use vars qw($VERSION %IRSSI);
use Irssi;
$VERSION = '0.0.3';
%IRSSI = (
authors => 'Thorsten Leemhuis',
contact => 'fedora@leemhuis.info',
name => 'fnotify',
description => 'Write a notification to a file that shows who is talking to you in which channel.',
url => 'http://www.leemhuis.info/files/fnotify/',
license => 'GNU General Public License',
changed => '$Date: 2007-01-13 12:00:00 +0100 (Sat, 13 Jan 2007) $'
);
#--------------------------------------------------------------------
# In parts based on knotify.pl 0.1.1 by Hugo Haas
# http://larve.net/people/hugo/2005/01/knotify.pl
# which is based on osd.pl 0.3.3 by Jeroen Coekaerts, Koenraad Heijlen
# http://www.irssi.org/scripts/scripts/osd.pl
#
# Other parts based on notify.pl from Luke Macken
# http://fedora.feedjack.org/user/918/
#
#--------------------------------------------------------------------
#--------------------------------------------------------------------
# Private message parsing
#--------------------------------------------------------------------
sub priv_msg {
my ($server,$msg,$nick,$address,$target) = @_;
filewrite($nick." " .$msg );
}
#--------------------------------------------------------------------
# Printing hilight's
#--------------------------------------------------------------------
sub hilight {
my ($dest, $text, $stripped) = @_;
if ($dest->{level} & MSGLEVEL_HILIGHT) {
filewrite($dest->{target}. " " .$stripped );
}
}
#--------------------------------------------------------------------
# The actual printing
#--------------------------------------------------------------------
sub filewrite {
my ($text) = @_;
# FIXME: there is probably a better way to get the irssi-dir...
open(FILE,">>$ENV{HOME}/.irssi/fnotify");
print FILE $text . "\n";
close (FILE);
}
#--------------------------------------------------------------------
# Irssi::signal_add_last / Irssi::command_bind
#--------------------------------------------------------------------
Irssi::signal_add_last("message private", "priv_msg");
Irssi::signal_add_last("print text", "hilight");
#- end
#!/bin/sh
# $argv = %r %h
# 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 -i .ssh/personal.pem -q $1@$2 -o PermitLocalCommand=no "> .irssi/fnotify; tail -f .irssi/fnotify" |
while read heading message; do
terminal-notifier -title "${heading}" -message "* ${message}";
done)&
Host personal
Hostname <<HOSTNAME-GOES-HERE>>
User <<USERNAME-GOES-HERE>>
PermitLocalCommand yes
LocalCommand ~/bin/irc_notify.sh %r %h
@lancelakey
Copy link

https://github.com/alloy/terminal-notifier

or

gem install terminal-notifier

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