Amateur Topologist

Politics, programming, math, and science.

Tag: irssi

Irssi, ssh, and screen: Three great tastes that go great together

If you’re a total IRC addict like I am, then it can be extremely handy to have a client running 24/7 in case something interesting happens and your computer is off or whatever; if you have logging on, then you can just scroll through the logs. But the only way I know of to do this is to use Irssi, a terminal-based IRC client for Linux/Unix (although OSX ports do exist, and it can be installed on a Windows machine using cygwin). The long and short of it is: you SSH into a remote server and run Irssi under a screen session. If you know what all that means, great, you can go do that now; skip down to the ‘configuration” section below. If not, I’ll walk you through it step by step.

Setup

  1. Get a shell account on a server somewhere. This very well may be the hardest step for some; I don’t know offhand of any easily-obtainable free servers that will allow you to run Irssi under screen. Most of them either forbid long-running processes or any sort of IRC out right, due to abuse. I happen to know someone who gave me a shell account on their server, so I can’t speak as to the reliability of any free/paid servers that might be out there. If you have a computer that’s always on and runs Linux, you can install openssh via your distribution’s package manager and use that instead. Make sure to forward port 22 on your router, obviously.
  2. Get Irssi installed on that server. If you have admin rights on the server, then you can just install it via whatever package manager; otherwise, you’ll have to ask the admin nicely to do this for you.
  3. Start up Irssi under screen. Connect to the server and run screen -U; if all goes well, you should see a totally blank screen except for a new prompt. You are now inside screen, which is like a subshell inside your existing shell, only it won’t quit when you close the window. To get out of screen, press Ctrl-a and then d; to get back in, run screen -raAdU. You can make new ‘windows’ inside screen with Ctrl-a, c (meaning ctrl-a followed by a c) and delete them with Ctrl-a, k; use Ctrl-a, n and Ctrl-a,p to switch between windows. Once you have a screen window set up, just run irssi.

An Irssi primer

If you know how to work irssi, you can skip this part and go on down to the Configuration section. If you don’t, read on.

Irssi supports all the usual commands: /whois, /msg, /join, /connect, etc. But there are two major differences you’re going to have to get used to. The most obvious one is that, by default, you can only have one window visible at a time. You can switch via /win <number>, or by pressing Alt followed by the number of the window (using 10 for window 0); the letters q through o on the keyboard are mapped to windows 11-19. You can move windows around by switching to whatever window and using /win move <number>, and close windows with /win close <number> or just plain /wc <number>. Omit the <number> to close the current window. Alt-a will move you to a window with ‘activity’; I’m not sure how it picks which window to move you to though.

The statusbar indicates which windows have had some sort of activity since you saw them last; dark green indicates a /join or /part or something similar, white indicates someone actually saying something, and hot pink means that someone said your name or someone PM’d you. But I use a script called adv_windowlist, and I recommend you do too; it makes keeping track of windows much easier.

The other thing that you’ll need to keep in mind when using Irssi is that whenever you tell it to join a channel, open up a query with a person, etc., it’ll join the channel on the network you’re currently on, if you’re in a window with a channel or query open, or if you’re in the special status window (window 1), whichever network’s name is specified in the statusbar. You can switch the latter by pressing ctrl-X.

Configuration

Half the reason that you might want to set up in this way is so that you can log every conversation; useful in case there’s a dispute in a channel. Irssi doesn’t log by default, but you can easily enable it: simply /set autolog on. You can chagne the timestamps in the log by adjusting log_timestamp; I personally use “%H:%M:%S ” (without quotes, note the space after the S!), which produces lines of the form

23:31 <@Waxx> No magic ever, under any circumstances.

You can also set the irc autolog path via the variable autolog_path; it accepts the special variables $tag, which is the name of the server the channel/query is on, $0, the name of the query or channel itself. It also accepts all the special strings listed here, although the ones you’re most likely to use are %Y for the four-number year, %m for the two-digit month, and %d for the two-digit day. So, for example, an autolog_path setting of ~/irclogs/$tag/%Y/$0-%m-%d.log would produce logfiles at, say, ~/irclogs/synirc/2009/#site19-07-22.log.

One of Irssi’s key strengths is its ability to be customized by the end-user via perl scripts. Installation is simple; put them in your scripts directory, ~/.irssi/scripts, and then run them via /load scriptname.pl. If you want them to automatically run, put them in ~/.irssi/scripts/autorun and run them with /load autorun/scriptname.pl. The twothat I couldn’t live without are:

  • splitlong.pl: Automatically splits long lines you copy-paste into Irssi to get around IRC’s character line limit. Install and forget; no configuration necessary.
  • adv_windowlist.pl: Converts the window list into something actually useful: lists all your windows in a grid, along with their names. After downloading, running, and installing it, you might as well remove the standard activity statusbar itemwith /statusbar window remove act as it’s now redundant. You can modify how the window looks by following the instructions in adv_windowlist.pl; personally, I use
    /set awl_display_key $Q%K|%n$H$C$S
    /set awl_block -15

    to pad each window’s entry out to 15 symbols and to make each entry be hilighted appropriately as well as have the alt-keymap for that window (if available) prepended to the window name or have the window’s number (if not). Regardless, you should run

    /statusbar window remove act

    to remove the ‘activity’ window, as adv_windowlist.pl renders it redundant.

There you have it; now you should be able to use irssi proficiently. As always, leave questions in the comments. I haven’t covered some of the other stuff you can do, such as theming and setting up automatic rejoin, but this post is getting long as it is and so I think I’ll put those in another post. Happy IRCing!