]> git.rmz.io Git - dotfiles.git/blob - awesome/utils.lua
aweome: move signals to own file
[dotfiles.git] / awesome / utils.lua
1 local utils = { }
2 utils.rules = { }
3 utils.globalkeys = { }
4
5 local host = io.popen("hostname")
6 utils.host = host:read("*l")
7
8 function utils.run_or_kill(command)
9 -- Check throught the clients if the class match the command
10 local lower_command=string.lower(command)
11 for k, c in pairs(client.get()) do
12 -- apparently some steam games don't have a client class
13 if c.class ~= nil then
14 local class=string.lower(c.class)
15 if string.match(class, lower_command) then
16 for i, v in ipairs(c:tags()) do
17 c:kill()
18 return
19 end
20 end
21 end
22 end
23 awful.util.spawn(command)
24 end
25
26 -- http://awesome.naquadah.org/wiki/Autostart#Simple_way
27 function utils.run_once(prg,arg_string,pname,screen)
28 if not prg then
29 do return nil end
30 end
31
32 if not pname then
33 pname = prg
34 end
35
36 if not arg_string then
37 awful.util.spawn_with_shell("pgrep -f -u $USER -x '" .. pname .. "' || (" .. prg .. ")",screen)
38 else
39 awful.util.spawn_with_shell("pgrep -f -u $USER -x '" .. pname .. " ".. arg_string .."' || (" .. prg .. " " .. arg_string .. ")",screen)
40 end
41 end
42
43
44 function utils.joinTables(t1, t2)
45 for k,v in ipairs(t2) do table.insert(t1, v) end return t1
46 end
47
48 function utils.rules.append(rules)
49 awful.rules.rules = awful.util.table.join(awful.rules.rules, rules)
50 end
51
52 function utils.globalkeys.append(keys)
53 globalkeys = awful.util.table.join(globalkeys, keys)
54 end
55
56 return utils