/articles/irssi last modified 30.478 days ago

How to Efficiently Use Irssi and Screen

Contents:

Background

I have been using Linux as my primary desktop operating system since July of 2003. For quite a while, I used X-Chat as my primary IRC client, but I wasn't impressed with the features X-Chat offered. It seemed uncustomizable and static. After a few months of using X-Chat, I tried irssi and immediately found it to be the most intuitive and easy to use IRC client yet. It has the features I want in an IRC client and I have been using irssi ever since. I have already succeeded in converting a few of my friends to Irssi, and with this guide, I hope to show the light to others.

Help spread the word of Irssi, link to this guide!

<a href="http://quadpoint.org/articles/irssi" target="_blank">
 A Guide to Efficiently Using Irssi and Screen
</a>

Before reading this guide, you should have some basic Linux knowledge. You should also have a shell on which Irssi and screen are installed.

Introduction

Irssi is a text-only IRC client. It does not get in your way and its commands are intuitive and useful. Non-standard features are implemented with perl scripts, rather than in the core. Irssi can range from a functional, no-frills client to a highly-customized and automated client.

Irssi is not the only focus of this guide. The ingenious program screen will also be discussed. Screen is a highly useful tool that allows a user to manipulate multiple windows inside of a single session. Each window operates independently of the others and acts like another terminal. For example, a user can create a screen session with Irssi running in the first window, an instant messenger program open in the second window, and a general purpose shell prompt in the third window. The beauty of the screen is that users can "detach" from their screens, logout, and then at a later time, login again "reattach" to find their programs still running just as they left them. The steps to do this will be explained in this guide.

Irssi Basics

The first step is to start irssi. Run from your shell:

irssi

You should now see Irssi in its default state--disconnected, with some blue bars at the top and bottom.

In Irssi, there are three important connection-related commands: /server, /connect, and /disconnect. Irssi can handle multiple IRC connections simultaneously, thus it is possible to be active in channels on different networks at the same time. The first command, /server, will connect to the specified server on the current network. On the other hand, /connect will open a new network connection and connect to the specified server on the new network.

For example, typing /connect irc.foo.com will open a new network connection and connect to irc.foo.com. If you then type /connect irc.bar.com, there will be two network connections open, one for irc.foo.com, one for irc.bar.com. Typing /server irc.baz.com while the network connection for irc.bar.com is active will disconnect the client from irc.bar.com and connect to irc.baz.com on that network connection. Read this paragraph again so it sinks in, and then move on.

You can use Ctrl-X to switch between network connections. You can see what the active network is by looking at the status bar, which looks something like this:
(05:23:10) (f0rked[+abilorsuwxyz]) (1:NullIRC (change with ^X)) (NullIRC is the active network connection)

At this point you should have a just-opened instance of Irssi, with no connections to any server. Connect to an IRC server by typing:

/connect irc.quadpoint.org

If everything connected fine, join a channel by typing:

/join #test

You should now notice that the "status" window is now gone, and you're looking at the channel you just joined. You should also notice that your status bar says "2:#test". This means that the window for #test is assigned window number 2. The status window is by default window number 1. To switch between windows in Irssi, use Alt-#, where # is 0-9. Windows start at number 1, and Alt-0 goes to window number 10. You can use Alt-q through Alt-o for windows 11 to 19. It is possible to have more than 19 windows. Use Alt with the arrow keys to scroll through the windows. Tip: if you're trying to get to end windows past 19, start at window 1, and then use Alt with the left arrow key.

Note: in some cases, using Alt as the modifier for window switching does not work. Macs have this 'problem'; the alt key on Mac OS X's terminal does not send an escape by default. The escape key may usually be used as a replacement for Alt for switching windows. If you'd like to use your Mac's Alt key to send an escape and properly switch windows in Irssi, do the following:

Terminal.app (10.5 Leopard)

  1. Choose "Preferences" from the Terminal.app menu
  2. In the "Settings" group, choose your profile.
  3. Go to the "Keyboard" tab
  4. Check "Use option as meta key"

Terminal.app (10.4)

  1. Choose "Window Settings" from the Terminal menu
  2. Choose "Keyboard" from the dropdown in the dialog that pops up
  3. Check "Use option key as meta key"
  4. Click Use Settings as Default

iTerm

  1. Choose "Manage Profiles" from the Bookmarks menu
  2. Expand "Keyboard Profiles"
  3. Select "Global"
  4. Select "Option Key as +Esc"

Once you're comfortable with the window switching, join another channel on the network and talk with people. Open a private message using:

/q nick

/q is short for /query. Both commands work, as /q is just an alias for /query. Irssi has many default aliases that aid in controlling your IRC client more quickly and easily. You can see them using /alias and looking at your status window.

Once you've finished typing in your query, type /q in the window to close it. Closing windows can also be accomplished using /wc (an alias for /window close). Using the /wc method is useful for parting channels on disconnected networks. In these cases, simply using /part will not work.

If you're still reading this, you've learned the basics of using Irssi--connecting, joining channels, opening and closing query windows, and switching through windows. Continue reading to learn more about Irssi's other features and commands.

More Irssi

Switch to your status window and type /set. You'll see your screen scroll with various setting = value lines. Use page up and page down to look through them (sometimes it is necessary to hold shift down while using these keys). These are the configurable settings of your IRC client. You can specify which ones in particular you'd like to see, instead of viewing all of them, by including a keyword after /set. Try: /set timestamp. The output should look something like this:

05:50 [lookandfeel]
05:50 timestamps = ON
05:50 timestamp_format = %H:%M
05:50 timestamp_timeout = 
05:50 timestamp_level = ALL

The setting of timestamp_format controls the appearance of the timestamps used in the client. I personally prefer having the seconds also displayed. To set this, type:

/set timestamp_format %H:%M:%S

Once you change a setting, use:

/save

to save your changes to your Irssi config file, located at ~/.irssi/config.

Now would be a good time to learn of Irssi's tab-completion feature. One of the most fantastic features of Irssi is it's ability to complete a nickname, variable, or file using the tab key. Try typing /set time, and instead of pressing enter, press the tab key. You will notice that Irssi completes the variable name. Press tab repeatedly to scroll through the matching variables. You can also use the tab completion to complete nicknames in channels or query windows by typing out the first few letters of their name and pressing tab.

Most non-standard functionality is added through the use of perl scripts. There is a large database of these scripts available at scripts.irssi.org. To use them, download the perl scripts to your ~/.irssi/scripts directory, and then type:

/run scriptname

Put the scripts (or symbolic links to them) in ~/.irssi/scripts/autorun to make them load automatically when Irssi starts. It's important that you read the top of each script you download; usually there is documentation there of some kind explaining the settings for the script. I recommend installing the following scripts:

splitlong.pl
dispatch.pl
chanact.pl
usercount.pl

Read their descriptions and comments for explanations of what they do.

By now you should have a good start to using Irssi for your needs. Irssi is simple to use. You can learn a great deal about Irssi by reading its help. Yes, help files actually contain useful information! You Windows users might be surprised by this, but they do. Type /help in Irssi to get a full list of commands (including those from perl addon scripts) in your status window. To see detailed information a particular command, use /help command. I highly suggest trying:

/help network

The /network command manages the networks that Irssi knows about. If you define the networks that you frequent, you can set multiple servers for a particular network and then simply use /server network name to connect to that network. If the first server fails, the next server in the list you defined with /network will be tried. You can also define a command to send to the server upon connection to the network. This is useful for automatic identification to a NickServ service or opering up, if you have an o:line.

Important note: the /network command replaced /ircnet in Irssi version 0.8.10. If you are using irssi 0.8.9, ask your system administrator to upgrade and use /ircnet in the meantime.}

Learning Screen

Screen is a wonderful program that creates a "session" in which several "windows" exist. In each window is a shell prompt, from which commands can be executed and programs can be run. With screen, a user can "detach" from his or her screen session, log out, eat some runts, log back in, and reattach to the screen session and find it in the same condition as it was left. Read on for a demonstration.

If you have Irssi open, use /quit to close it. When you're back at your shell prompt, start screen:

screen

You should be immediately returned to a shell prompt. You're now inside of your screen. You can see this by typing screen -list

f0rked@godfather f0rked $ screen -list
There is a screen on:
        7517.pts-0.godfather    (Attached)
1 Socket in /var/run/screen/S-f0rked.

Now, type irssi. If you took the time earlier to define your networks with /network, you can type irssi -c network name here to automatically connect to the desired network. Irssi should open as it did before, but now it's running inside of screen.

There are certain keystrokes that you can make inside of a screen session to control it. The commands are in the format of Ctrl-A,letter, usually. This is executed by pressing the control key and the 'a' key at the same time, releasing both, and then pressing letter. At this point you should learn to detach from your screen session. Press ctrl-a,d to do this (Press ctrl-A, release, press d). When this is done, you should see something like "[detached]" print to your terminal. If you see this, you're no longer in screen, but Irssi is still running in it, in the background. For effect, feel free to disconnect from your shell completely and then log back in before continuing to the next step.

You should be at your shell prompt right now, outside of screen. Before, you typed screen to run it. Running screen with no arguments creates a new screen session. You can have multiple screen sessions, but this will not be discussed here. Read the manpage of screen for more information. Since you have already created a screen session, you do not want to make a new one, you want to reattach to the one you already created. To do this, type:

screen -raAd

The arguments "-raAd" tell screen what you want it to do: reattach, do some sizing stuff (a,A), and detach before reattaching if necessary. These arguments are safe to use in just about every case. If your screen session is attached elsewhere, using -raAd will detach that session, and reattach it here.

Magically, irssi should have reappeared. This is the point where you stand back for a moment and say "Wow, that kicks ass," because now you should understand that you can leave Irssi running all the time under screen, detach from screen and disconnect from your shell, come back later, login and reattach and there Irssi will be. You should also see that with screen, you will have the ability to log in from anywhere and continue your IRCing (or whatever work you're doing in another screen window) just as you left it. Yes, it's good, I know.

Congratulations, you just learned the basics of screen. Now you should learn how to create new windows inside of screen. This is done by typing C-a c (this is how it is written in the screen manpage. It means Ctrl-a,c). As new windows are created, you will be automatically switched to them. You can navigate through screen windows using C-a #, starting at zero, so Ctrl-a,0 should take you back to Irssi. Here's a cheat sheet (from the screen manpage):

The following table shows the default key bindings:

C-a 0       (select 0)
...           ...
C-a 9       (select 9)
C-a C-a     (other)    Toggle  to  the  window  displayed previously.
C-a a       (meta)     Send the command character (C-a) to  window.  See  escape
				   command.
C-a A       (title)    Allow the user to enter a name for the current window.
C-a c
C-a C-c     (screen)   Create  a new window with a shell and switch to that win-
				   dow.
C-a C       (clear)    Clear the screen.
C-a d
C-a C-d     (detach)      Detach screen from this terminal.
C-a D D     (pow_detach)  Detach and logout.
C-a k
C-a C-k     (kill)        Destroy current window.
C-a space
C-a n
C-a C-n     (next)        Switch to the next window.
C-a w
C-a C-w     (windows)     Show a list of window.
C-a ?       (help)        Show key bindings.

Take a moment to look over those commands. They should tell you how to basically operate screen, especially the last one. There are plenty more, use Ctrl-a,c and then type man screen for the full list.

Before you disconnect from your shell, make sure you detach from your screen using the appropriate detach sequence.

Troubleshooting:
If you mess up and screen doesn't seem to work correctly, remember to use screen -list (or screen -ls) to see where you are. You should pay attention to whether or not you are attached, detached, or if screen is running at all.

If you end up with multiple screen sessions, you have to specify which session when you want to attach. If this is not desired, kill one of the sessions by first using screen -list to find the id of the session. The id will look something like 8037.tty1.godfather. With the id in hand, run:

screen -X -S ID kill

to kill the screen session with id ID.

Customizing Irssi's Display

Ample time should be spent adjusting the apperance of irssi to make the client suitable for you. This includes changing the theme, adding or splitting windows, and manipulating the statusbars. I'll go over the basics of how to obtain my current Irssi setup, which looks like this:

irssi thumbnail

Theme

The theme only changes the colors of text and objects in Irssi, as well as some symbols used in the statusbars. The ">>" used at the beginning of the statusbars in my screenshot is there because of the theme I'm using. The theme used in that screenshot is my own hack of the irssi default themes called fear2.

To load a new theme, download the .theme file into ~/.irssi, then use /set theme fear2 in irssi, where "fear2" is the part of the filename before .theme. Don't forget to /save if you want to keep that theme setting.

Hilight Window

See the numbered version of my irssi screenshot. The section labeled "1" is a split window called "hilight". Anything that is hilighted (set using the /hilight command) will be logged to that window.

To do this, first load the script. The script I use is a modified version of cras' hilightwin.pl that logs timestamps as well. It is available here: hilightwin.pl
Put the script in ~/.irssi/scripts/autorun/ and type /run autorun/hilightwin.pl in irssi.

Next, create the split window. This is done with the /window command. See /help window for details on how this works.

/window new split
/window name hilight
/window size 6

The above commands will create a new split window (as opposed to a "hidden" window, which privmsg, channel, and status windows are by default), call it hilight (so the script knows where to send the information) with a height of 6 lines.

Now, have someone address you in a channel using "yournick: hello". If you did everything correctly, it should be logged to the split window. If you want to have all lines containing your nick hilighted, type /hilight yournick. See /help hilight for advanced features. Use /layout save to save your layout settings and have irssi automatically recreate the split hilight window on startup.

Statusbar

See number 2 in the numbered screenshot. This is the default statusbar that you will see in any default irssi setup. However, mine is slightly modified to include a user count of the current channel. This is easily done by loading the usercount.pl script and typing /statusbar window add usercount in irssi.

Channel Statusbar Using Advanced Windowlist

This is my favorite part of my Irssi setup. See number 3 of the numbered screenshot, and my updated screenshot. In each screenshot, chanact.pl and adv_windowlist.pl are used, respectively, to list the windows open in irssi. As of October 16, 2005, this article explains the setup of awl (Advanced Windowlist) instead of chanact.

Download adv_windowlist.pl (known as 'awl'). This is a fabulous script that grants powerful manipulation of the active window list. Put the script in ~/.irssi/scripts/autorun and run it: /run autorun/adv_windowlist.pl

Upon loading, awl will create new statusbars on its own. AWL is an updated version of the older chanact.pl script. AWL has many, many new features developed by Nei. It would be worth your time to read the comments at the top of the script to get a feel for what all you can do with it (an entire article could be written on the features of this script and how to use them).

Now would be a good time to remove the standard Act statusbar item. If you're unfamiliar with what I'm talking about, the act object is the part of the default statusbar that says (Act: 2) when window 2 has activity. With awl loaded, you won't need it anymore.

/statusbar window remove act

You can see all available settings (which will be listed in your status window) for awl by typing /set awl. The possible settings and explanations for them are listed at the top of the awl script. The current settings I am using for awl are:

/set awl_display_key $Q%K|%n$H$C$S
/set awl_block -15

If you like the setup, type /save to keep it. You can revert to the old act setup using /script unload awl and /statusbar window add act -after lag.

Irssi Command Reference

Here is a list of common commands, aliases, and some tips on using them. Usage and additional information can be obtained by typing /help /command in irssi. I have compiled a full help file of all of the commands in HTML form for viewing, here.

Command Alias Info
/ban/bans, /bSets or List bans for a channel
/clear/c, /clClears a channel buffer
/join/jJoins a channel
/kick/kKicks a user
/kickban/kbKickban a user
/msg/mSend a private message to a user
/unban */mubClears the unbanlist (unbans everyone) in a channel
/names/nLists the users in the current channel
/topic/tDisplays/edits current topic. Tip: use /t[space][tab] to automatically fill in existing topic.
/window close/wcForce closure of a window.
/whois/wiWHOIS a user. Displays user information

Tips

When selecting URLs using a double-click, the Windows SSH client PuTTY will choke on the colon and possibly some other characters. You can fix this by changing the character class of these troublesome characters in the PuTTY options under Window -> Selection to match the character class of typical alphanumeric characters (which is '2' at the time of this writing). Essentially, this changes what PuTTY considers to be a 'word' when double-clicking.

Linux terminal emulator programs also have this problem. I use rxvt-unicode (urxvt), which has a resource option called cutchars (read the manpage for urxvt). The default setting BACKSLASH `"'&()*,;<=>?@[]{|} breaks 'words' on any of those characters.

However, adding this to your ~/.Xdefaults file will adjust urxvt so that URLs containing & , = ? ; will not break words so they can be selected entirely with one double-click:

URxvt*cutchars: `"()'*<>[]{|}

Resources

Happy Irssi-ing and screening. You may use man irssi and man screen at a command prompt for more detailed information about both of the programs discussed in this guide. Read Irssi's help with /help to learn about useful features not discussed in this tutorial, and also visit the following sites:

$Date: 2008-01-01 22:18:08 -0600 (Tue, 01 Jan 2008) $