[xmonad] make DynamicLog prefix workspace names with number

Omari Norman omari at smileystation.com
Mon Feb 1 13:41:41 EST 2010

Hi Lara,

> Following up on this question, is it possible to have the log
> automatically set the name of the workspace to the programs running in
> it? 

Can't help you there :( I'm rudimentary with xmonad and haskell...

2010/1/30 Omari Norman <omari at smileystation.com>:

> Is there any easy way to get DynamicLog to prefix the names of
> workspaces with numbers?

I cobbled together something rudimentary in zsh. Surely this could be
done in Haskell using the ppOutput function in dynamicLog, and maybe
when I have a few minutes to mess around with Haskell I'll do that. This
is very primitive--workspace names can't have spaces--but it does
(currently) work, in case someone else finds it handy.

-------------- next part --------------

# xmobar_with_ws_numbers - takes output from xmonad intended for
# xmobar. Changes the workspaces portion, adding workspace numbers.
# Then, pipes the output to xmobar.
# Assumes there are only alphanumeric characters [a-zA-Z0-9] in
# workspace names, and it will likely choke on anything that's not
# ASCII. Thus you can't have spaces or symbols in workspace names.

# Given a workspace number on $1 and the entire workspace text on
# $2, echoes the workspace text with a workspace number added.
# Takes into account the format of xmobar input, which has xml-like
# tags to indicate colors.
addNumber() {
    if echo $2 | grep -q '<'; then
        echo -n $2 | sed -r 's/>([a-zA-Z0-9]*)</>'$1':\1</'
        echo -n "$1:$2"

while read line; do
    workspaces_str=$(echo $line | cut -d: -f 1)
    workspaces_arr=(${(s: :)workspaces_str})
    for num in $(seq 1 ${#workspaces_arr}); do
        addNumber $num ${workspaces_arr[$num]}
        echo -n ' '
    echo -n ':'
    echo $line | cut -d: -f 2-
done | xmobar

More information about the xmonad mailing list