+local utils = { }
+local io = { popen = io.popen }
+local string = { match = string.match,
+ lower = string.lower}
+
+utils.rules = { }
+utils.globalkeys = { }
+
+local host = io.popen("hostname")
+utils.host = host:read("*l")
+
+function utils.is_dir(path)
+ return os.execute(('[ -d "%s" ]'):format(path))
+end
+
+local function terminal_cmd(prg, name)
+ local join = require("gears.table").join
+ local term_cmd = {terminal}
+ if name then
+ if terminal:match("rxvt") then
+ term_cmd = join(term_cmd, {"-name", name})
+ end
+ end
+ return join(term_cmd, {"-e", prg})
+end
+
+function utils.spawn_terminal(prg, cprop, cb)
+ if not cprop then
+ cprop = {}
+ end
+ local name = cprop.instance
+ awful.spawn(terminal_cmd(prg, name), cprop, cb)
+end
+
+function utils.spawn_terminal_once(prg, rules, matcher, unique_id, cb)
+ local name = rules.instance
+ awful.spawn.once(terminal_cmd(prg, name), rules, matcher, unique_id, cb)
+end
+
+function utils.run_or_kill(prg, cprop, screen)
+ if not prg then
+ do return nil end
+ end
+
+ if not cprop then
+ cprop = { }
+ end
+
+ if not cprop.class then
+ cprop.class = prg
+ end
+
+ if not cprop.instance then
+ cprop.instance = ""
+ end
+
+ cprop.class = string.lower(cprop.class)
+ cprop.instance = string.lower(cprop.instance)