Browsing the archives for the Useful programs category

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!

2 Comments

tsocks: Make any application SOCKS-compatible

Most applications that require Internet access have at least some form of SOCKS compatibility to allow the usage of proxies, but not all of them do. That’s where tsocks comes in; it overrides certain internal functions of the programs you tell it to load and redirects them through its own versions, which are SOCKS-aware and hence can be used through ssh tunnels, etc. tsocks is dead simple to set up and install; Ubuntu users can just grab it from repositories, or get the raw source files here. Then create a file named /etc/tsocks.conf by running

gksu gedit /etc/tsocks.conf

and adding a line

server = myserver.com

; that’s it! If your SOCKS server runs on a non-standard port, or requires a username and password, add lines assigning to server_port, default_user, or default_pass respectively.

Using tsocks is easy; if you want to run a single command using tsocks, just add tsocks to the beginning, like

tsocks pidgin

. To make all programs use tsocks until further notice, just run

tsocks

with no arguments; it’ll create a shell within your shell. To exit back out and stop using tsocks, just type

exit

to exit the subshell.

0 Comments

Gnome-Do: easy keyboard launching for Linux

This is the first entry in what I hope will be a regular series: highlighting a useful Linux application that I use and that I think would benefit a significant number of people, as well as providing (Ubuntu-centered) installation and configuration instructions. I intend to keep a Monday/Thursday schedule, although certain events (more on those in a later post) might disrupt my schedule, as well as my general posting for the next couple of weeks.

GNOME-Do is probably one of the most useful programs for any operating system I have ever used, aside from basics such as word processing, music playing, and web browsing. It lets you search for applications and launch them, post to Twitter, control your music, open Firefox bookmarks, and even open ssh and VNC sessions, all without having to drop down into a command line.

Installation

Although the default Ubuntu repositories do carry it, their versions are relatively out of date; I recommend you use the official Do repositories. To do this, open up /etc/apt/sources.list as root (such as by typing

gksu gedit /etc/apt/sources.list

in a terminal) and add these two lines, replacing jaunty with hardy or intrepid as appropriate:

deb http://ppa.launchpad.net/do-core/ubuntu jaunty main
deb-src http://ppa.launchpad.net/do-core/ubuntu jaunty main

Then save and run

sudo apt-get update

from a terminal to update your package database, and then

sudo apt-get install gnome-do gnome-do-plugins

to install it. Users of other operating systems, or users who want to build from source, can visit the official Do wiki’s installation instructions.

Use

GNOME-Do should automatically start up whenever you log in; if it doesn’t, you might need to tell it to do so. On Ubuntu, you can do this by opening Startup Applications under System->Preferences (Sessions on older versions) and adding a new entry, putting gnome-do as the command. Once you have Do running, try pressing Super-Space (Super is usually the windows key if you have it). If this doesn’t work or you want a different keybinding, change the keybinding by right-clicking on the tray icon, selecting Preferences, and editing the ‘Summon’ shortcut. In any case, you should see a window with two search panes, the item pane on the left and the action pane on the right, appear in the center of your screen. This is Do. To launch a program, start typing its name, and eventually Do should recognize which program you want. If it doesn’t, try pressing up and down to scroll through the list. If you still don’t find it, you might need to try using a different name for it; Do pulls its names from the Ubuntu menu. For example, to launch gedit, type ‘Text Editor’. Note that you don’t need to type the entire name; all that’s necessary is that it show the proper program in the left pane. If you need to cancel, press the Escape key or press the Summon key combination again.

Plugins

Of course, Do is really useful only when combined with plugins, which can be enabled by launching ‘Preferences’ from Do (or right-clicking on the tray icon and selecting Preferences). Here are some of my personal favorites:

ssh

If you have various hosts that you ssh to often, Do can simplify the process. If you haven’t already, open up ~/.ssh/config and add the hosts in the format:

HostName myhostalias
User myremoteusername
HostName myhost.com

If you need more customization, read the ssh_config manpage.
Then enable the ssh plugin, and try typing the name of one of your hosts. The words ‘Connect with SSH’ should appear in the action pane; if they don’t, press tab and select them by pressing up and down. Hit enter to connect; Do will launch a terminal When you log out or the connection is lost, the terminal will auto-close. You can also type ‘Connect with SSH” or some substring in the Item pane and select the host from the action pane; you can even type in an arbitrary host and Do will try to connect to it, using any options you may have added

1 Comment