init.lua 538 B

123456789101112131415161718192021
  1. local wibox = require("wibox")
  2. local awful = require("awful")
  3. battery_widget = wibox.widget.textbox()
  4. battery_widget:set_align("right")
  5. function update_battery(widget)
  6. local cmd = "acpi | awk '{if($1 == \"Battery\"){print substr( $4, 1, length($4) - 1 )}}'"
  7. local fd = io.popen(cmd)
  8. local status = fd:read("*l")
  9. fd:close()
  10. widget:set_markup("B: "..status)
  11. end
  12. update_battery(battery_widget)
  13. mytimer = timer({ timeout = 10 })
  14. mytimer:connect_signal("timeout", function () update_battery(battery_widget) end)
  15. mytimer:start()