]> git.rmz.io Git - dotfiles.git/blobdiff - awesome/utils.lua
Merge branch 'master' of tardis:/dotfiles
[dotfiles.git] / awesome / utils.lua
index f534770af6f48aacdd5810a0318d89bc9201e6d1..8bbf3400941d2cf8de6cd4c353bdef8b9c537ab7 100644 (file)
@@ -1,5 +1,6 @@
 local utils = { }
-
+utils.rules = { }
+utils.globalkeys = { }
 
 local host = io.popen("hostname")
 utils.host = host:read("*l")
@@ -8,15 +9,48 @@ function utils.run_or_kill(command)
     -- Check throught the clients if the class match the command
     local lower_command=string.lower(command)
     for k, c in pairs(client.get()) do
-        local class=string.lower(c.class)
-        if string.match(class, lower_command) then
-            for i, v in ipairs(c:tags()) do
-                c:kill()
-                return
+        -- apparently some steam games don't have a client class
+        if c.class ~= nil then
+            local class=string.lower(c.class)
+            if string.match(class, lower_command) then
+                for i, v in ipairs(c:tags()) do
+                    c:kill()
+                    return
+                end
             end
         end
     end
     awful.util.spawn(command)
 end
 
+-- http://awesome.naquadah.org/wiki/Autostart#Simple_way
+function utils.run_once(prg,arg_string,pname,screen)
+    if not prg then
+        do return nil end
+    end
+
+    if not pname then
+       pname = prg
+    end
+
+    if not arg_string then 
+        awful.util.spawn_with_shell("pgrep -f -u $USER -x '" .. pname .. "' || (" .. prg .. ")",screen)
+    else
+        awful.util.spawn_with_shell("pgrep -f -u $USER -x '" .. pname .. " ".. arg_string .."' || (" .. prg .. " " .. arg_string .. ")",screen)
+    end
+end
+
+
+function utils.joinTables(t1, t2)
+    for k,v in ipairs(t2) do table.insert(t1, v) end return t1
+end
+
+function utils.rules.append(rules)
+    awful.rules.rules = awful.util.table.join(awful.rules.rules, rules)
+end
+
+function utils.globalkeys.append(keys)
+    globalkeys = awful.util.table.join(globalkeys, keys)
+end
+
 return utils