diff options
author | Jonathan McCrohan <jmccrohan@gmail.com> | 2017-07-09 18:37:37 +0100 |
---|---|---|
committer | Jonathan McCrohan <jmccrohan@gmail.com> | 2017-07-09 18:37:37 +0100 |
commit | aefae07bde1937197dabea9233c484efd8228252 (patch) | |
tree | 1574e1fe7fc72dcea6703dc64f975ae2339ba473 /.config/awesome/functions/run_once.lua | |
download | awesome-aefae07bde1937197dabea9233c484efd8228252.tar.gz |
Initial commit of my awesome configuration
Diffstat (limited to '.config/awesome/functions/run_once.lua')
-rw-r--r-- | .config/awesome/functions/run_once.lua | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/.config/awesome/functions/run_once.lua b/.config/awesome/functions/run_once.lua new file mode 100644 index 0000000..7c57482 --- /dev/null +++ b/.config/awesome/functions/run_once.lua @@ -0,0 +1,35 @@ +local awful = require("awful") +local lfs = require("lfs") + +local function processwalker() + local function yieldprocess() + for dir in lfs.dir("/proc") do + if tonumber(dir) ~= nil then + local f, err = io.open("/proc/"..dir.."/cmdline") + if f then + local cmdline = f:read("*all") + f:close() + if cmdline ~= "" then + coroutine.yield(cmdline) + end + end + end + end + end + return coroutine.wrap(yieldprocess) +end + +function run_once(process, cmd) + assert(type(process) == "string") + local regex_killer = { + ["+"] = "%+", ["-"] = "%-", + ["*"] = "%*", ["?"] = "%?" } + + for p in processwalker() do + if p:find(process:gsub("[-+?*]", regex_killer)) then + return + end + end + return awful.spawn(cmd or process) +end +-- run once END |