All patches and comments are welcome. Please squash your changes to logical
commits before using git-format-patch and git-send-email to
patches@git.madduck.net.
If you'd read over the Git project's submission guidelines and adhered to them,
I'd be especially grateful.
4 Licensed under GNU General Public License v2
5 * (c) 2013, Luke Bonham
6 * (c) 2010-2012, Peter Hofmann
7 * (c) 2010, Adrian C. <anrxc@sysphere.org>
11 local awful = require("awful")
12 local debug = require("debug")
16 -- Lain helper functions for internal use
20 helpers.lain_dir = debug.getinfo(1, 'S').source:match[[^@(.*/).*$]]
21 helpers.icons_dir = helpers.lain_dir .. 'icons/'
22 helpers.scripts_dir = helpers.lain_dir .. 'scripts/'
26 function helpers.wrequire(table, key)
27 local module = rawget(table, key)
28 return module or require(table._NAME .. '.' .. key)
34 -- If lain.terminal is a string, e.g. "xterm", then "xterm -e " .. cmd is
35 -- run. But if lain.terminal is a function, then terminal(cmd) is run.
37 function helpers.run_in_terminal(cmd)
38 if type(terminal) == "function"
41 elseif type(terminal) == "string"
43 awful.util.spawn(terminal .. ' -e ' .. cmd)
49 -- {{{ Format units to one decimal point
51 function helpers.uformat(array, key, value, unit)
52 for u, v in pairs(unit) do
53 array["{"..key.."_"..u.."}"] = string.format("%.1f", value/v)
60 -- {{{ Read the first line of a file or return nil.
62 function helpers.first_line(f)
69 local content = fp:read("*l")
78 helpers.map_table = {}
80 function helpers.set_map(element, value)
81 helpers.map_table[element] = value
84 function helpers.get_map(element)
85 return helpers.map_table[element]