about summary refs log tree commit diff
path: root/.local/bin/rofi-powermenu
diff options
context:
space:
mode:
authorvenomade <venomade@venomade.com>2026-02-11 11:42:58 +0000
committervenomade <venomade@venomade.com>2026-02-11 11:42:58 +0000
commit0bd150185551b6d8835d022c15a5f6e832d51113 (patch)
tree10bf3f3443df49a44eb47b328b73b7e76b0a4924 /.local/bin/rofi-powermenu
parent8d688d1107c46b6dfdcaf02fa5c9c4c8a4640e65 (diff)
Asahi
Soft reset of dotfiles specific to Asahi, Sway and Neovim.
Diffstat (limited to '.local/bin/rofi-powermenu')
-rwxr-xr-x.local/bin/rofi-powermenu49
1 files changed, 49 insertions, 0 deletions
diff --git a/.local/bin/rofi-powermenu b/.local/bin/rofi-powermenu
new file mode 100755
index 0000000..0ff3f9c
--- /dev/null
+++ b/.local/bin/rofi-powermenu
@@ -0,0 +1,49 @@
+#!/usr/bin/env lua
+
+local function rofi(prompt, lines)
+  local cmd = string.format(
+    'printf "%s" | rofi -dmenu -i -p "%s"',
+    table.concat(lines, "\n"),
+    prompt
+  )
+  local handle = io.popen(cmd)
+  local selection = handle:read("*a")
+  handle:close()
+  selection = selection:gsub("%s+$", "")
+  if selection == "" then return nil end
+  return selection
+end
+
+local function contains(tbl, val)
+  for _, v in pairs(tbl) do
+    if v == val then
+      return true
+    end
+  end
+  return false
+end
+
+-- TODO: Deduplicate This
+local options = {
+  "Log Out",
+  "Shutdown",
+  "Restart"
+}
+
+local option_pair = {
+  ["Log Out"] = "swaymsg exit",
+  ["Shutdown"] = "systemctl poweroff",
+  ["Restart"] = "systemctl reboot"
+}
+
+local choice = rofi("Action:", options)
+if (not choice) or (not contains(options,choice)) then os.exit() end
+
+if choice == "Log Out" then
+  io.popen(option_pair[choice])
+else
+  local confirm = rofi("Are you sure?:", {"Yes", "No"})
+  if confirm == "Yes" then
+    io.popen(option_pair[choice])
+  end
+end