Make sure Emacs server is running! Now use this bit of Lisp:
(defvar my/erc-aggressive-status-clear t
"Setting this to t means that when you make a channel ``visible''
by unminimizing the Emacs frame or switching to its virtual
desktop, said channel will be removed from the status string. (To
be precise, we call `org-modified-channels-update' from the
polling function `my/erc-status', so there will be a delay
according to your polling interval.) Otherwise you'd need to
manually trigger `erc-modified-channels-update' by, e.g.,
switching windows. Note that, if `my/erc-aggressive-status-clear'
is enabled, you should ensure that `erc-track-visibility' is set
to `visible' or `selected-visible'. Otherwise, ANY channel that
has a window (even if the frame is minimized) will be removed
from the status string during polling.")
(with-eval-after-load 'erc
;; See docstring for `my/erc-aggressive-status-clear'.
(setq erc-track-visibility 'visible)
(add-to-list 'erc-modules 'track))
(defun my/erc-status ()
(when (and (boundp 'erc-track-shorten-function)
(functionp erc-track-shorten-function))
(when my/erc-aggressive-status-clear (erc-modified-channels-update))
(let* ((chan-bufs (mapcar 'car erc-modified-channels-alist))
(chan-names (mapcar 'buffer-name chan-bufs))
(short-names (funcall erc-track-shorten-function chan-names)))
(s-concat "[" (s-join "," short-names) "]"))))
A bit of bash:
#!/bin/bash
(! pidof emacs >/dev/null 2>&1) && exit
status=$(emacsclient -e '(my/erc-status)' 2>/dev/null)
# $? != 0 ==> my/erc-status doesn't exist (or it error'd)
# nil ==> ERC isn't loaded
# "[]" ==> no activity
[[ $? != 0 || $status == "nil" || $status == '"[]"' ]] && exit
status=${status:1:${#status}-2} # strip surrounding quotes
echo $status
# echo "<fc=#00aaff>$status</fc> |" # colorful xmobar status w/ divider
Now just configure your status bar to run this script periodically. For Xmobar, it’ll look something like
Config { commands = [ Run Com "erc-status.sh" [] "erc" 50, ... ]
, sepChar = "%"
, template = "%erc% ..."
, ...
}
This will update the status every 5 seconds.
Inspired by http://blog.mpg.is/2013/04/using-xmobar-to-display-rcirc-status.html