Created
May 3, 2021 00:57
-
-
Save troglobit/24411dca2204bb03ae6daf10b99419c0 to your computer and use it in GitHub Desktop.
Fixed runonce.lua for AwesomeWM
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- @author Peter J. Kranz (Absurd-Mind, [email protected]) | |
-- Any questions, criticism or praise just drop me an email | |
local awful = require("awful") | |
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 |
The code above is just an example, YMMV. The x-window-manager is a shortcut/alternative on Debian/Ubuntu derived systems. Usually ends up as a symlink in /etc/alternatives.
Gotcha, thanks. The script worked fine on my old system and apparently does not on my new system. It's both Debian, so that's why I was confused.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
So,
pgrep -o $USER awesome
yields nothing on my new system. There is no process calledawesome
, sogetCurrentPid
returns-1
.There is, however, a process called
x-window-manager
. This patch seems to make it work again:Is this the right fix? Anyone know what is going on?