Categories
Computers

Awesome and uzbl

I spent a little time and finally came up with a fairly simple start to integrating Awesome with uzbl. I created a file called favorites and put it in a suitably obscure location. The file format is simply 2 double-quoted fields per line. The first field is a site name, the second is the url. The fields are space separated. For example:

"Mutt"    "www.mutt.org"

Lua pattern matching is fairly restrictive, so this was the simplest way to get a lot of possibilities for the name and the url fields.

Using that format, the following piece of Lua code in my Awesome configuration does the trick:

wwwmenu_t = {}
function wwwmenuinit()
local path = os.getenv("XDG_CONFIG_HOME")
if not path then
path = os.getenv("HOME") .. "/.config"
end
for line in io.lines(path .. "/uzbl/favorites") do
local t = {}
local site, url = string.match(line, "^\"(.+)\"%s+\"(.+)\"$"
table.insert(t, site)
table.insert(t, "uzbl " .. url)
table.insert(wwwmenu_t, t)
end
wwwmenu = awful.menu.new({ items = wwwmenu_t })
end

I just call the function to build the menu, then bind a key to toggle it like so:

awful.key({modkey}, "w", function () wwwmenu:toggle() end)

The menu pops up and I can select a website. I’ve concocted my own version of dynamic tagging in Awesome so when uzbl launches, it gets its own tag. I don’t have to worry about cluttering up the current tag I’m on as a result.

I’ve also bound uzbl to the “u” key:

awful.key({modkey}, "u", function () awful.util.spawn("uzbl") end)

So I can just launch it directly from keystrokes. Since I’ve coded “run-or-raise” functionality into my configuration, if uzbl is already running, pressing “modkey-u” will just jump me over to the tag with my uzbl instances. I don’t have the run-or-raise code shown here.

It would be nice if I could sort the wwwmenu_t as well to make finding an entry in the popup menu easier. A limitation here is that Awesome has to be restarted to update the menu with new entries in the favorites file. Not sure how to overcome that- possibly stat’ing the favorites file on the key press and recalling the init function if it’s been updated. I’m sure something is possible.

UPDATE- Corrected Lua code for path error.

Leave a Reply

Your email address will not be published. Required fields are marked *