GNOME Workspace Wraparound

I found out yesterday that GNOME (or more correctly, the GNOME window manager, Metacity) only allows you to switch to a specific workspace. You cannot cycle through workspaces, wrapping around to the first when on the last. There is a long-standing upstream bug report, about this issue, but sadly it is marked as wontfix.

I have, however, found a workaround using wmctrl. These commands could obviously be much nicer if they were placed in a proper script, but I wanted a one line snippet that I could add to my xbindkeys config. This allows me to execute these commands using keyboard shortcuts.

# Workspace Increment
wmctrl -s $(( $(( $(wmctrl -d | sed -n 's/^\([0-9]\+\) *\*.*/\1/p') + 1 )) & 3 ))

# Workspace Decrement
wmctrl -s $(( $(( $(wmctrl -d | sed -n 's/^\([0-9]\+\) *\*.*/\1/p') - 1 )) & 3 ))

Note: In order to minimise the calls to wmctrl, I've hardcoded my number of workspaces (4 in my case) as a bitwise AND in the last portion of these commands.

XML reindent

XML is designed to be human-readable. However, to minimise data transfer, the indentation and newline characters are often discarded during transmission. This results in a difficult-to-read XML file such as the one below:

<?xml version="1.0" encoding="ISO-8859-1"?><note><to>Tove</to><from>Jani</from>
<heading>Reminder</heading><body>Don't forget me this weekend!</body></note>

This XML file can be both checked for validity, and reindented using xmllint. Debian/Ubuntu users can find this as part of the libxml2-utils package.

xmllint --format input.xml > output.xml

This results in the following, more-sane output:

<?xml version="1.0" encoding="ISO-8859-1"?>
  <body>Don't forget me this weekend!</body>

GNU Screen Autostart

I got a Debian based VPS recently, and every so often I find myself needing to reboot the server. I keep forgetting to start my GNU Screen and Irssi windows again though.

Adding the following line to /etc/rc.local allows GNU Screen to automatically run at boot time. This line runs Screen from my unpriviledged account, loads Irssi within that Screen, and then backgrounds itself, ready for the next time I login.

/bin/su unprivilegeduser -c "/usr/bin/screen -dmS sessionname /usr/bin/irssi"

EDIT: I've since ditched Screen in favour of tmux, and moved to a crontab for starting irssi after restarts.

Place the following in your local crontab file:

@reboot /usr/bin/tmux new-session -d -n irssi /usr/bin/irssi