Last active
August 29, 2015 13:56
-
-
Save daGrevis/9163163 to your computer and use it in GitHub Desktop.
Battery widget for awesome (using acpi)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Just an experiment. You will probably want to use Vicious widget for battery.