powermenu.lua 748 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #!/usr/bin/env luajit
  2. -- Use a list because table keys are randomly sorted
  3. -- It's also easier to add options or edit them this way
  4. local options = {
  5. {
  6. name = "Sleep",
  7. icon = "system-suspend",
  8. command = "systemctl suspend",
  9. },
  10. {
  11. name = "Shut down",
  12. icon = "system-shutdown",
  13. command = "systemctl poweroff",
  14. },
  15. {
  16. name = "Restart",
  17. icon = "system-reboot",
  18. command = "systemctl reboot",
  19. },
  20. {
  21. name = "Lock",
  22. icon = "system-lock-screen",
  23. command = "swaylock",
  24. },
  25. {
  26. name = "Log out",
  27. icon = "system-log-out",
  28. command = "swaymsg exit",
  29. },
  30. }
  31. for i, opt in ipairs(options) do
  32. if arg[1] then
  33. if opt.name == arg[1] then
  34. os.execute(opt.command)
  35. end
  36. else
  37. print(opt.name .. "\0icon\x1f" .. opt.icon)
  38. end
  39. end