IRC done right with ii

Sun, 16 November, 2008

IRC is a guilty pleasure. Logically, I know I've never gotten any value out of it. It's largely vacuous chat. Hanging out on ##c on freenode, any reasonable lurkers like myself are mesmerized by the comedy of people who are a) students trying to get homework "help" or b) embittered veterans who enjoy helping people like Nurse Ratchet enjoys helping her patients.

Nonetheless, I can't stay away. I guess I like the activity clicking down my screen every few seconds - I feel important and connected (don't think about that too hard).

ii is the only IRC client that has made sense to me. Rather than try to wrap the protocol into a custom interface with a custom scripting setup, ii gives you the protocol as a filesystem, and lets you define your own interface & pluggability through standard tools or shell capabilities. And at < 500 lines of dependency-free code, it's light as a feather.

So, how to use ii effectively? You guessed it, I have a shell function! The function sends the output of one channel to the console, formatted my way (= no presence messages or timestamps). screen is used to set up multiple windows.

Sending a message requires echo'ing to a flat file, but since I'm a lurker it's fine with me if it's hard to accidentally spam a channel when I think a different window is focused (a sadly common thing in a tiling window manager).

Here's the shell function from my .bashrc

# Usage: jn \#\#c  -- or -- jn \#\#c irc.freenode.net
# First form defaults to irc.freenode.net

function jn {

        IRCNAME=aurous

        # init
        IRC_HOST=irc.freenode.net
        if [ $2 ]; then
                IRC_HOST=$2
        fi

        SERVER_ROOT=~/irc/$IRC_HOST
        CHANNEL_ROOT=$SERVER_ROOT/$1

        # Truncate old irc log to last few lines
        if [ -f $CHANNEL_ROOT/out ]; then
                tail -n 1000 $CHANNEL_ROOT/out > $CHANNEL_ROOT/outnew
                rm $CHANNEL_ROOT/out
                mv $CHANNEL_ROOT/outnew $CHANNEL_ROOT/out
        fi

        # Start ii for this server if not running
        #if   ! ( ii procs   get command-line                      started with same server
        if( [ ! "`pgrep ii | xargs -I xxx echo /proc/xxx/cmdline | xargs -I xxx grep $IRC_HOST xxx`" ] ); then
                ii -n $IRCNAME -s $IRC_HOST &
                sleep 1
        fi

        # Join the channel
        echo "/j $1" > $SERVER_ROOT/in
        sleep 1

        # Check that we're connected to the channel
        if [ -f $CHANNEL_ROOT/out ]; then
                # tail
                tail -f $CHANNEL_ROOT/out | 
                while read ln; do 
                        #        strip presence lns   strip date/time stamp           let grep hilite nicks
                        echo $ln | grep -v "\-\!\-" | sed -e 's/^.................//' | grep "<(.*\)>"
                done
        else
                echo Failure, couldnt read $CHANNEL_ROOT/out, probably no such channel
        fi
}

About Me

Erik Mackdanz is a software developer in Austin, Texas, along with everybody else.

Links