Saturday, April 20, 2013

Using xmobar to display rcirc status from emacs

I use the emacs rcirc as my main irc client, and via BitlBee, facebook and skype chat. I use XMonad as my window manager, and xmobar as my display bar. Today I added the rcirc status line to my xmobar, so that I can see if I have new messages on any channels/facebook chat/skype. I wrote a short bash scriptlet that I execute in xmobar with

Run Com "~/.scritpstouse/rcircActivity" [] "rcirc" 100

the script is as follows:

#!/usr/bin/env bash
if  emacsclient -e rcirc-activity-string > rcirc-string;then
    if ircstr=$(cat rcirc-string | tr '"' '\n' | grep '\[');then
        echo "<fc=#00ff00>"$ircstr"</fc>"
    else
        echo "<fc=#0000ff>[]</fc>"
    fi
else
    echo "<fc=#ff0000>[]</fc>"
fi

This contacts my running emacs server and asks for the status string, and then displays it. I'd have it in the .xmobarrc, but it doesn't handle escaped " so well. If my server isn't running or rcirc isn't, there is no field that contains [, so the output will be empty and my xmobar will just have a few spaces. The echos give me different colors on the xmobar based on what happened, green and the status if rcirc on, blue if emacs on but rcirc not, and red if emacs turned off. Try it!

[Edit: I've decided to try and use erc instead. The command is almost the same (the ircActivity), but the if clause is replaced with:
i
f  ercBuffers=$(emacsclient -e "(if (functionp erc-track-shorten-function) (funcall erc-track-shorten-function (mapcar 'buffer-name (mapcar 'car erc-modified-channels-alist))) (nil))");then
    if ircstr=$(echo ${ercBuffers:1:${#ercBuffers}-2} | tr ' ' ',' | tr -d '"');then
        echo "<fc=#00ff00>["$ircstr"]</fc>"


A little more complicated, but it works, and I believe erc is more feature rich.]

I'll later try to explain my xmonad config, and include the (current) file. It handles everything for me, from handling my workpaces, windows etc.. to changing my keyboardlayout and handling my media keys. It rocks!