I'm trying to improve my rc.lua
for the Awesome window manager. The default rc.lua
sets up a menu with the following code:
myawesomemenu = {
{ "manual", terminal .. " -e man awesome" },
{ "edit config", editor_cmd .. " " .. awesome.conffile },
{ "restart", awesome.restart },
{ "quit", awesome.quit }
}
I use Awesome as the window manager for the GNOME desktop environment, so I want to have Awesome use the gnome-session-quit
program instead of awesome.quit
, but only if the environment variable "DE" is set to "gnome". Therefore, I replaced the fifth line with
{ "quit", if os.getenv("DE") == "gnome" then os.execute("/usr/bin/gnome-session-quit") else awesome.quit end }
But when I reload the file, I get "unexpected symbol near if". How can I fix this, and what causes it?
Try this:
{ "quit", (os.getenv("DE") == "gnome") and function() os.execute("/usr/bin/gnome-session-quit") end or awesome.quit}
a and b or c
is like the C expression a ? b : c
, provided that b
is not false
.
I'm pretty sure Lua doesn't work like that :P
Have you tried wrapping it in a function?
{
"quit",
function()
if os.getenv("DE") == "gnome" then
os.execute("/usr/bin/gnome-session-quit")
else
awesome.quit
end
end
}
Can you also try rewriting awesome.quit
instead?
_awesome_quit = awesome.quit
awesome.quit = function()
if os.getenv("DE") == "gnome" then
os.execute("/usr/bin/gnome-session-quit")
else
_awesome_quit()
end
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With