2 local io = { popen = io.popen }
3 local string = { match = string.match,
9 local host = io.popen("hostname")
10 utils.host = host:read("*l")
12 function utils.is_dir(path)
13 return os.execute(('[ -d "%s" ]'):format(path))
16 local function terminal_cmd(prg, name)
17 local join = require("gears.table").join
18 local term_cmd = {terminal}
20 if terminal:match("rxvt") then
21 term_cmd = join(term_cmd, {"-name", name})
24 return join(term_cmd, {"-e", prg})
27 function utils.spawn_terminal(prg, cprop, cb)
31 local name = cprop.instance
32 awful.spawn(terminal_cmd(prg, name), cprop, cb)
35 function utils.spawn_terminal_once(prg, rules, matcher, unique_id, cb)
36 local name = rules.instance
37 awful.spawn.once(terminal_cmd(prg, name), rules, matcher, unique_id, cb)
40 function utils.run_or_kill(prg, cprop, screen)
49 if not cprop.class then
53 if not cprop.instance then
57 cprop.class = string.lower(cprop.class)
58 cprop.instance = string.lower(cprop.instance)
60 for k, c in pairs(client.get()) do
61 -- apparently some steam games don't have a client class
62 if c.class == nil then
65 local class=string.lower(c.class)
66 local instance=string.lower(c.instance)
67 if string.match(class, cprop.class) and string.match(instance, cprop.instance) then
68 for i, v in ipairs(c:tags()) do
74 awful.spawn.with_shell(prg, screen)
77 -- http://awesome.naquadah.org/wiki/Autostart#Simple_way
78 function utils.run_once(prg,arg_string,pname,screen)
87 if not arg_string then
88 awful.spawn.with_shell("pgrep -f -u $USER -x '" .. pname .. "' || (" .. prg .. ")",screen)
90 awful.spawn.with_shell("pgrep -f -u $USER -x '" .. pname .. " ".. arg_string .."' || (" .. prg .. " " .. arg_string .. ")",screen)
94 function utils.get_default_sink()
95 local f = io.popen('pactl get-default-sink')
98 return string.match(line, "^sink%s*%d*%s*(.-)%s")
101 function utils.joinTables(t1, t2)
102 for k,v in ipairs(t2) do table.insert(t1, v) end return t1
105 function utils.rules.append(rules)
106 awful.rules.rules = gears.table.join(awful.rules.rules, rules)
109 function utils.globalkeys.append(keys)
110 globalkeys = gears.table.join(globalkeys, keys)
113 function utils.has_battery()
114 return utils.is_dir("/sys/class/power_supply/BAT0")