How to growl IRC messages over ssh

My environment

I'm using weechat on remote server's screen.
The big problem is I can't perceive chatting on IRC without "polling" terminal by myself. Because I have no way to get alert over screen and ssh.

I was thinking to solve this problem and just found the solution.

The flow is:

  1. Use weechat's logging function
  2. Connect to remote server over ssh, tail -f your logs
  3. Receive the multiple lines then process it with perl on your local machine and growl!

Preparation

  • Enable weechat's logging function and find the log files.
  • Confirm that the following command works well (rewrite the path to logs)
tail -f $HOME/.weechat/logs/*/*/*.weechatlog
  • Install `growlnotify`

Setup scripts

Shell script that connecting to the server (irc_growl.sh)

You may have to rewrite ssh options and path to the log. Be careful with `'` (single quotation mark) to guaranteeing the home dir path is interpolated with remote's.

ssh example.com tail -n 1 -f '$HOME/.weechat/logs/*/*/*.weechatlog' | perl irc_growl.pl &
Perl script that processes received lines (irc_growl.pl)

You can rewrite system()'s args as you want. `man growlnotify` will help you.

while (<STDIN>) {
    chomp;
    next unless $_;
    next if /^==>/; # ignore tail's output

    my $attr = parse($_);
    if ($attr->{type} =~ /(:?NOTICE|PRIVMSG)/) {
        system("growlnotify", "-m", $attr->{content}, "-t", $attr->{user}, "--appIcon", "LimeChat");
    }
}

sub parse {
    my ($line) = @_;

    my ($time, $cmd, @contents) = split /\t/, $line;
    my $content = join "\t", @contents;

    my $user;
    if (not $cmd) {           # critical error
        $cmd = 'ERROR';
    } elsif ($cmd eq '-->') { # join
        $cmd = 'JOIN';
    } elsif ($cmd eq '<--') { # part
        $cmd = 'PART';
    } elsif ($cmd eq '--') {  # messages from server
        $cmd = 'SERVER';
    } elsif ($cmd eq '*') {   # notice
        $user = $cmd;
        $cmd = 'NOTICE';
    } else {                  # privmsg
        $user = $cmd;
        $cmd = 'PRIVMSG';
    }

    return +{
        type    => $cmd,
        time    => $time,
        content => $content,
        user    => $user,
    };
}

Run!

./irc_growl.sh