]> git.rmz.io Git - dotfiles.git/blob - awesome/utils.lua
zsh: vi-mode and new prompt
[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(command)
13 -- Check throught the clients if the class match the command
14 local lower_command=string.lower(command)
15 for k, c in pairs(client.get()) do
16 -- apparently some steam games don't have a client class
17 if c.class ~= nil then
18 local class=string.lower(c.class)
19 if string.match(class, lower_command) then
20 for i, v in ipairs(c:tags()) do
21 c:kill()
22 return
23 end
24 end
25 end
26 end
27 awful.util.spawn(command)
28 end
29
30 -- http://awesome.naquadah.org/wiki/Autostart#Simple_way
31 function utils.run_once(prg,arg_string,pname,screen)
32 if not prg then
33 do return nil end
34 end
35
36 if not pname then
37 pname = prg
38 end
39
40 if not arg_string then
41 awful.util.spawn_with_shell("pgrep -f -u $USER -x '" .. pname .. "' || (" .. prg .. ")",screen)
42 else
43 awful.util.spawn_with_shell("pgrep -f -u $USER -x '" .. pname .. " ".. arg_string .."' || (" .. prg .. " " .. arg_string .. ")",screen)
44 end
45 end
46
47 function utils.get_default_sink()
48 local f = io.popen('ponymix defaults --short')
49 line = f:read('*l')
50 f:close()
51 return string.match(line, "^sink%s*%d*%s*(.-)%s")
52 end
53
54 function utils.joinTables(t1, t2)
55 for k,v in ipairs(t2) do table.insert(t1, v) end return t1
56 end
57
58 function utils.rules.append(rules)
59 awful.rules.rules = awful.util.table.join(awful.rules.rules, rules)
60 end
61
62 function utils.globalkeys.append(keys)
63 globalkeys = awful.util.table.join(globalkeys, keys)
64 end
65
66 return utils