tag/ ruby

I recently switched to ruby-wmii as my window manager. Among its other features, it's a tagging window manager. This means that instead of virtual desktops, you have views. Each view is essentially a single tag, and the windows shown in that view are the ones with that particular tag.

wmii provides all sorts of bindings for tagging and retagging windows, and also provides a binding to start a window on a new tag (normally, the window would start tagged with your current view). This usually works great, but what if I want to run an app and have it show up on another tag, from a shell prompt? Not available in the base setup, but hey, that's why it's written in Ruby.

So, after a crash course in Ruby, here's what I came up with. First, add this:

# Hack to tag "next" window from shell or elsewhere
@nexttag = ""
register("NextWindowTags", nil, nil) {|tag,| @nexttag = tag }
on_createclient do |cid|
    if @nexttag != ""
        write("/client/#{cid}/tags", @nexttag )
        @nexttag = ""

to your wmiirc-config.rb. This lets you send an external event that saves tags to be used for the next window created. Then, in your .bash_profile or elsewhere, add this:

function on () {
    echo "NextWindowTags $TAG" | wmiir write /event


Now, you can run whatever you want, on whatever tag (or tags) you want, from the shell. For example:

on coding xterm

would run a new xterm and tag it for display in the 'coding' view.

on mail+misc+irc xclock

would start xclock, and tag it for display in all of 'mail', 'misc', and 'irc'.

Posted Sat 16 May 2009 01:45:14 AM UTC Tags: ruby