]> git.rmz.io Git - dotfiles.git/blob - awesome/utils.lua
awesome: fix typo
[dotfiles.git] / awesome / utils.lua
1 local utils = { }
2 local io = { popen = io.popen }
3 local string = { match = string.match,
4 lower = string.lower}
5
6 utils.rules = { }
7 utils.globalkeys = { }
8
9 local host = io.popen("hostname")
10 utils.host = host:read("*l")
11
12 function utils.run_or_kill(prg, cprop, screen)
13 if not prg then
14 do return nil end
15 end
16
17 if not cprop then
18 cprop = { }
19 end
20
21 if not cprop.class then
22 cprop.class = prg
23 end
24
25 if not cprop.instance then
26 cprop.instance = ""
27 end
28
29 cprop.class = string.lower(cprop.class)
30 cprop.instance = string.lower(cprop.instance)
31
32 for k, c in pairs(client.get()) do
33 -- apparently some steam games don't have a client class
34 if c.class == nil then
35 return
36 end
37 local class=string.lower(c.class)
38 local instance=string.lower(c.instance)
39 if string.match(class, cprop.class) and string.match(instance, cprop.instance) then
40 for i, v in ipairs(c:tags()) do
41 c:kill()
42 return
43 end
44 end
45 end
46 awful.util.spawn_with_shell(prg, screen)
47 end
48
49 -- http://awesome.naquadah.org/wiki/Autostart#Simple_way
50 function utils.run_once(prg,arg_string,pname,screen)
51 if not prg then
52 do return nil end
53 end
54
55 if not pname then
56 pname = prg
57 end
58
59 if not arg_string then
60 awful.util.spawn_with_shell("pgrep -f -u $USER -x '" .. pname .. "' || (" .. prg .. ")",screen)
61 else
62 awful.util.spawn_with_shell("pgrep -f -u $USER -x '" .. pname .. " ".. arg_string .."' || (" .. prg .. " " .. arg_string .. ")",screen)
63 end
64 end
65
66 function utils.get_default_sink()
67 local f = io.popen('ponymix defaults --short')
68 line = f:read('*l')
69 f:close()
70 return string.match(line, "^sink%s*%d*%s*(.-)%s")
71 end
72
73 function utils.joinTables(t1, t2)
74 for k,v in ipairs(t2) do table.insert(t1, v) end return t1
75 end
76
77 function utils.rules.append(rules)
78 awful.rules.rules = awful.util.table.join(awful.rules.rules, rules)
79 end
80
81 function utils.globalkeys.append(keys)
82 globalkeys = awful.util.table.join(globalkeys, keys)
83 end
84
85 return utils