Saturday, May 4, 2013

BREW up a cup of IRSSI... it really is that easy!

This post inspired by:

MacPorts is fun, but BREW is even more fun!

I wanted to restart my old IRSSI spell check script tonight to catch up with some old pals on a number of IRC servers. It is never cool to have spell check issues while typing away on IRC, and I remembered back in the day I wrote what I thought was a small one liner - see below for how you can teach IRSSI to catch typoes and assorted beverage errors with the tab key. But, anyway, I was on OSX, so I needed to poke around with pkg management some...

First up BREW:

bash-3.2$ ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go)"
==> This script will install:
/usr/local/bin/brew
/usr/local/Library/...
/usr/local/share/man/man1/brew.1

Now to take a look at IRSSI:

http://graphicgraffiti.com.au/blog/2012/installing-irssi-with-proxy-on-mac-os-x/

bash-3.2$ brew install irssi --with-perl=yes --with-proxy
==> Downloading http://irssi.org/files/irssi-0.8.15.tar.bz2
######################################################################## 100.0%
==> Patching
patching file configure
Hunk #1 succeeded at 14050 (offset -13369 lines).
Hunk #2 succeeded at 14068 with fuzz 2 (offset -13369 lines).
patching file docs/irssi.1
==> ./configure --prefix=/usr/local/Cellar/irssi/0.8.15 --sysconfdir=/usr/local/etc --with-bot --with-proxy --
==> make
==> make install
/usr/local/Cellar/irssi/0.8.15: 288 files, 4.6M, built in 28 seconds

Oops! I hit up an issue with CPAN on OSX, which really slowed me down!
cpan[1]> o conf urllist unshift http://www.cpan.org
Please use 'o conf commit' to make the config permanent!

cpan[2]> o conf commit
commit: wrote '/System/Library/Perl/5.12/CPAN/Config.pm'

cpan[3]> install Bundle::CPAN
Fetching with LWP:
http://www.cpan.org/authors/01mailrc.txt.gz
Reading '/var/root/.cpan/sources/authors/01mailrc.txt.gz'
............................................................................DONE
Fetching with LWP:
http://www.cpan.org/modules/02packages.details.txt.gz
Reading '/var/root/.cpan/sources/modules/02packages.details.txt.gz'
  Database was generated on Sun, 05 May 2013 00:07:17 GMT
............................................................................DONE
Fetching with LWP:
http://www.cpan.o

(MUCH, MUCH, MUCH SNIPPAGE LATER)

Phew all set! now we can finally get to:
cpan[5]> i /aspell/
Distribution    HANK/Text-Aspell-0.09.tar.gz
Module  < Meta::Tool::Aspell     (VELTZER/Meta-0.08.tar.gz)
Module  < Pod::Spelling::Aspell  (LGODDARD/Pod-Spelling-0.17.tar.gz)
Module  < Text::Aspell           (HANK/Text-Aspell-0.09.tar.gz)
4 items found                                                            

And then finally my old irssi script works:
/load spell.pl
22:51 -!- Irssi: Loaded script spell

Woot!

Here is the IRSSI script if you fancy tab complete spell check...
cat spell.pl 
# Usage:
# /load spell.pl
# 23:19 -!- Irssi: Loaded script spell

# As you type, if you hit *tab* it will complete the current word
# with the best suggestion, and print the top 5 matches in the 
# scroll buffer

use strict;
use vars qw($VERSION %IRSSI);
use Text::Aspell;
use Irssi;

$VERSION = '1.00';
%IRSSI = (
 authors     => 'core',
 contact     => 'core',
 name        => 'aspell spell check',
 description => 'spell checker',
 license     => 'Public Domain',
);

my $speller = Text::Aspell->new;

Irssi::signal_add_last 'complete word' => \&spell;

sub spell {
 my $out = "";
 my ($complist, $window, $word, $linestart, $want_space) = @_;
  if (!$speller->check($word)){
   my @suggestions = $speller->suggest($word);
    if (@suggestions){
    push @$complist, $suggestions[0];
    for (my $i=0;$i<8 data-blogger-escaped-.="" data-blogger-escaped-i="" data-blogger-escaped-out="" data-blogger-escaped-window-="">print("$out");
   }
  }
}

[any opinions here are all mine, and have absolutely nothing to do with my employer]
(c) 2011 James Cuff