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 function utils.spawn_terminal(prg, cprop, cb)
17 local join = require("gears.table").join
18 local term_cmd = {terminal}
19 if cprop and cprop.instance then
20 if terminal:match("rxvt") then
21 term_cmd = join(term_cmd, {"-name", cprop.instance})
24 awful.spawn(join(term_cmd, {"-e", prg}), cprop, cb)
27 function utils.run_or_kill(prg, cprop, screen)
36 if not cprop.class then
40 if not cprop.instance then
44 cprop.class = string.lower(cprop.class)
45 cprop.instance = string.lower(cprop.instance)
47 for k, c in pairs(client.get()) do
48 -- apparently some steam games don't have a client class
49 if c.class == nil then
52 local class=string.lower(c.class)
53 local instance=string.lower(c.instance)
54 if string.match(class, cprop.class) and string.match(instance, cprop.instance) then
55 for i, v in ipairs(c:tags()) do
61 awful.spawn.with_shell(prg, screen)
64 -- http://awesome.naquadah.org/wiki/Autostart#Simple_way
65 function utils.run_once(prg,arg_string,pname,screen)
74 if not arg_string then
75 awful.spawn.with_shell("pgrep -f -u $USER -x '" .. pname .. "' || (" .. prg .. ")",screen)
77 awful.spawn.with_shell("pgrep -f -u $USER -x '" .. pname .. " ".. arg_string .."' || (" .. prg .. " " .. arg_string .. ")",screen)
81 function utils.get_default_sink()
82 local f = io.popen('ponymix defaults --short')
85 return string.match(line, "^sink%s*%d*%s*(.-)%s")
88 function utils.joinTables(t1, t2)
89 for k,v in ipairs(t2) do table.insert(t1, v) end return t1
92 function utils.rules.append(rules)
93 awful.rules.rules = gears.table.join(awful.rules.rules, rules)
96 function utils.globalkeys.append(keys)
97 globalkeys = gears.table.join(globalkeys, keys)
100 function utils.has_battery()
101 return utils.is_dir("/sys/class/power_supply/BAT0")