Skip to content

Instantly share code, notes, and snippets.

@daGrevis
Last active August 29, 2015 13:56
Show Gist options
  • Select an option

  • Save daGrevis/9163163 to your computer and use it in GitHub Desktop.

Select an option

Save daGrevis/9163163 to your computer and use it in GitHub Desktop.
Battery widget for awesome (using acpi)
bat_widget = wibox.widget.textbox()
function set_bat(bat_widget)
local s = ""
local output = io.popen("acpi"):read()
if not output then
s = "N/A"
bat_widget:set_text(s)
return
end
local percentage = string.match(output, ".-(%d+)%%")
local time_left = string.match(output, ".-(%d+:%d+)")
local is_charging = string.find(output, "Charging") ~= nil
local is_full = string.find(output, "Full") ~= nil
s = string.format("%s%%", percentage, time_left)
if time_left then
s = s .. string.format("/%s", time_left)
end
if is_charging or is_full then
s = s .. " ↯"
end
bat_widget:set_text(s)
end
set_bat(bat_widget)
bat_timer = timer({ timeout = 10 })
bat_timer:connect_signal("timeout", function()
set_bat(bat_widget)
end)
bat_timer.start(bat_timer)
@daGrevis

Copy link
Copy Markdown
Author

Just an experiment. You will probably want to use Vicious widget for battery.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment