Sunday, April 12, 2015

weechat for xchat refugees.

As I was looking for ways to improve my screen real estate. I started looking for alternative irc clients to the graphical one I was using (xchat).

So I began to research different clients (ones that could be run from a terminal) and started a personal selection process.

My research lead me to two clients (irssi and weechat) and in the end I settled on weechat.
  • Note: This post is not to explain why I chose which client (I may do that in another post) however, this post is to document my move from xchat to weechat and how I made it feel similar to what I was used to.
I was inspired by Dennis Kaarsemaker's post on irssi for xchat refugees, and thus how I got the title for this post.

With that said, the weechat getting started guide is quite good, for any one starting with IRC or moving to the weechat client.

One of the hardest thing to understand (or find information on) about terminal based irc clients is what what each component of the main layout is or stands for.

Weechat in and of its self did not make this easy, however once you know where to look (the weechat users guide, on screen lay out), you quickly figure it out. In short, by default weechat gives you a chat area and 4 primary bar's (interactive areas). If you try and relate this to xchat its everything except the channels / servers (networks) list that you see on the left by default.

So out the door, weechat gets you fairly close to the default xchat layout with out having to do anything (this is nice if your looking to make a simple transition).

However while the title, input and nicklist bars are simple to understand/ decipher their content in the status bar left me baffled for some time. While its simple to understand the point of the status bar its contents were not clean until I looked up the configuration for weechat.bar.status.items.
/help weechat.bar.status.items
Option "weechat.bar.status.items":
  description: items of bar, they can be separated by comma (space between items) or "+" (glued items); special synta "@buffer:item" can be used to force buffer used when displaying the bar item
  type: string
  values: any string
  default value: "[time],[buffer_last_number],[buffer_plugin],buffer_number+:+buffer_name+(buffer_modes)+{buffer_nicklist_count}+buffer_zoom+buffer_filter,[lag],[hotlist],completion,scroll"
  current value: "[time],buffer_number+: +buffer_name,[lag],completion,scroll"
As you can see from the output I have changed my status bar to fit my needs, as I don't need or like all the default items. You can do the same, however the reason for explaining this again is to give you a reference for the default layout.

For someone used to xchat the channels/servers (networks) list will likely be important. To solve this, I went to the weechat plugin infrastructure and found 2 plugins (scripts), that build this list and keep it sorted in a similar way to xchat.

The buffers.pl script builds the channels/network (servers) list automatically and simply displays it to you. Installing it is quite simple, as it is with most plugins.
cd ~/.weechat/perl/autoload; wget https://weechat.org/files/scripts/buffers.pl
The next critical plugin to this layout (xchat conversion) is the autosort.py script that arages the channels/servers in alphabetical lists in the same way xchat does. Installing it is the same as the buffers.pl script above.
cd ~/.weechat/python/autoload; wget https://weechat.org/files/scripts/autosort.py
  • Note:  I find it easiest to restart weechat to pick up the changes, however I know (and I use), alternative methods to reload scripts / plugins.
The only other change I made to weechat was to make 2 setting modifications so that the channels/servers list is without numbers and is indented (similar to xchat).
/set buffers.look.show_number off
/set buffers.look.indenting on
And with that, you have a terminal based weechat client that looks and feels like xchat.

Because F11, maps to full screen (for most thing) and F12 is my hot key for the Gnome Dropdown Terminal I also make the following change to my weechat.conf file:
    diff weechat.conf{,_old}
    < meta2-23;3~ = "/bar scroll nicklist * -100%"
    < meta2-23~ = "/bar scroll nicklist * b"
    < meta2-24;3~ = "/bar scroll nicklist * +100%"
    < meta2-24~ = "/bar scroll nicklist * e"
    ---
    > meta2-23~ = "/bar scroll nicklist * -100%"
    > meta2-23;3~ = "/bar scroll nicklist * b"
    > meta2-24~ = "/bar scroll nicklist * +100%"
    > meta2-24;3~ = "/bar scroll nicklist * e"
    With this change I make the configuration a little more useful, by mapping alt+F1[1|2] to be the scroll for  the nick bar, as opposed to only being able to see the top or bottom.

    Another nice part about weechat is that plugins, like the hilight plugin,
    are not needed because weechat can use regular expressions or denote phases in its highlight setting.
    Option "weechat.look.highlight":
      description: comma separated list of words to highlight; case insensitive comparison (use "(?-i)" at beginning of words to make them case sensitive), words may begin or end with "*" for partial match; example: "test,(?-i)*toto*,flash*"
    One thing that is lacking from weechat that xchat has is gnome integration, with notifications. To be fair to weechat, as this is a terminal tool, the primary notification method is the terminal beep.

    To get such a gnome or GUI pop-up notification, I recommend using the lnotify.py (requires notify-python) plugin/script because of its simplicity.
    •  Note: on a Fedora system you can get this by running: 
    # sudo yum install notify-python.x86_64
    One issue I had with it was that Fedora does not have a 'weechat' icon, by default.

    Instead of making one (or finding one), I simply used one of the standard gnome icon names to set the plugins.var.python.lnotify.icon option (I use mail-unread), for the plugin, so that libnotify supply an image (instead of a blank space) sending notifications.

    I was even able to find, a way to start weechat, so that it looks / feels like a stand alone GUI application, within gnome! 
    To do this you can follow Gnome Desktop Files Developer's Guide, or you can simply create a file like the one below, and place it in /usr/share/applications.
    [Desktop Entry]
    Type=Application
    Encoding=UTF-8
    Name=WeeChat
    Comment=WeeChat GUI
    Exec=gnome-terminal --hide-menubar -e weechat
    Icon=application.png
    Terminal=false
    What this does is starts, a gnome terminal, and weechat within it. By hiding the gnome menu bar, the terminal and weechat start to look like any other gnome application. 
    With these simple modifications, I was able to quickly transition from xchat to weechat, and the following shows a side by side comparison of the transition.