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.run_or_kill(prg, cprop, screen)
25 if not cprop.class then
29 if not cprop.instance then
33 cprop.class = string.lower(cprop.class)
34 cprop.instance = string.lower(cprop.instance)
36 for k, c in pairs(client.get()) do
37 -- apparently some steam games don't have a client class
38 if c.class == nil then
41 local class=string.lower(c.class)
42 local instance=string.lower(c.instance)
43 if string.match(class, cprop.class) and string.match(instance, cprop.instance) then
44 for i, v in ipairs(c:tags()) do
50 awful.util.spawn_with_shell(prg, screen)
53 -- http://awesome.naquadah.org/wiki/Autostart#Simple_way
54 function utils.run_once(prg,arg_string,pname,screen)
63 if not arg_string then
64 awful.util.spawn_with_shell("pgrep -f -u $USER -x '" .. pname .. "' || (" .. prg .. ")",screen)
66 awful.util.spawn_with_shell("pgrep -f -u $USER -x '" .. pname .. " ".. arg_string .."' || (" .. prg .. " " .. arg_string .. ")",screen)
70 function utils.get_default_sink()
71 local f = io.popen('ponymix defaults --short')
74 return string.match(line, "^sink%s*%d*%s*(.-)%s") or ""
77 function utils.joinTables(t1, t2)
78 for k,v in ipairs(t2) do table.insert(t1, v) end return t1
81 function utils.rules.append(rules)
82 awful.rules.rules = awful.util.table.join(awful.rules.rules, rules)
85 function utils.globalkeys.append(keys)
86 globalkeys = awful.util.table.join(globalkeys, keys)
89 function utils.has_battery()
90 return utils.is_dir("/sys/class/power_supply/BAT0")