summaryrefslogtreecommitdiff
path: root/.config/awesome/runonce.lua
diff options
context:
space:
mode:
authorben <benjaminfranzke@googlemail.com>2010-08-30 23:41:28 +0200
committerben <benjaminfranzke@googlemail.com>2010-08-30 23:41:28 +0200
commitf230f3840c9097864c7238b636dee26219640e54 (patch)
treef72c714140813db897c8eb6bbdd8a07474f5ac5b /.config/awesome/runonce.lua
parent7232dbc89ff76f4554b0348122ed7dcd0888c80e (diff)
downloaddotfiles-f230f3840c9097864c7238b636dee26219640e54.tar.gz
dotfiles-f230f3840c9097864c7238b636dee26219640e54.tar.bz2
dotfiles-f230f3840c9097864c7238b636dee26219640e54.zip
add awesome wm config
Diffstat (limited to '.config/awesome/runonce.lua')
-rw-r--r--.config/awesome/runonce.lua74
1 files changed, 74 insertions, 0 deletions
diff --git a/.config/awesome/runonce.lua b/.config/awesome/runonce.lua
new file mode 100644
index 0000000..fd57cde
--- /dev/null
+++ b/.config/awesome/runonce.lua
@@ -0,0 +1,74 @@
+-- @author Peter J. Kranz (Absurd-Mind, peter@myref.net)
+-- Any questions, criticism or praise just drop me an email
+
+local M = {}
+
+-- get the current Pid of awesome
+local function getCurrentPid()
+ -- get awesome pid from pgrep
+ local fpid = io.popen("pgrep -u " .. os.getenv("USER") .. " -o awesome")
+ local pid = fpid:read("*n")
+ fpid:close()
+
+ -- sanity check
+ if pid == nil then
+ return -1
+ end
+
+ return pid
+end
+
+local function getOldPid(filename)
+ -- open file
+ local pidFile = io.open(filename)
+ if pidFile == nil then
+ return -1
+ end
+
+ -- read number
+ local pid = pidFile:read("*n")
+ pidFile:close()
+
+ -- sanity check
+ if pid <= 0 then
+ return -1
+ end
+
+ return pid;
+end
+
+local function writePid(filename, pid)
+ local pidFile = io.open(filename, "w+")
+ pidFile:write(pid)
+ pidFile:close()
+end
+
+local function shallExecute(oldPid, newPid)
+ -- simple check if equivalent
+ if oldPid == newPid then
+ return false
+ end
+
+ return true
+end
+
+local function getPidFile()
+ local host = io.lines("/proc/sys/kernel/hostname")()
+ return awful.util.getdir("cache") .. "/awesome." .. host .. ".pid"
+end
+
+-- run Once per real awesome start (config reload works)
+-- does not cover "pkill awesome && awesome"
+function M.run(shellCommand)
+ -- check and Execute
+ if shallExecute(M.oldPid, M.currentPid) then
+ awful.util.spawn_with_shell(shellCommand)
+ end
+end
+
+M.pidFile = getPidFile()
+M.oldPid = getOldPid(M.pidFile)
+M.currentPid = getCurrentPid()
+writePid(M.pidFile, M.currentPid)
+
+return M