-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrunonce.lua
41 lines (37 loc) · 1009 Bytes
/
runonce.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
require("lfs")
-- {{{ Run programm once
local function processwalker()
local function yieldprocess()
for dir in lfs.dir("/proc") do
-- All directories in /proc containing a number, represent a process
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
local 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.util.spawn(cmd or process)
end
-- }}}
-- Usage Example
run_once("nm-applet")
-- run_once("skype")
-- run_once("pidgin")