Skip to content

Instantly share code, notes, and snippets.

@jiphex
Last active August 29, 2015 14:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jiphex/333271919304787acc32 to your computer and use it in GitHub Desktop.
Save jiphex/333271919304787acc32 to your computer and use it in GitHub Desktop.
OpenBSD Battery widget for awesome 3.5

Include this in your ~/.config/awesome/rc.lua file and then add the widget at the same place you add your clock.

Output is like 69%[123] - the number in the square brackets is the minutes remaining (or ??)

Colour will be green if charging, white if battery is high, yellow if low or red if critical.

-- battery widget
function battery_status ()
-- note that whatever order you specify these flags in, ac status is always the last line
local fd=io.popen("apm -blma", "r") --list present batteries
local batstate = tonumber(fd:read())
local batpct = tonumber(fd:read())
local batmin = fd:read()
local acstate = tonumber(fd:read())
local color
if batstate == 3 or acstate == 1 then -- charging or AC green
color="<span color=\"lightgreen\">"
elseif batstate == 0 then -- high white
color="<span color=\"white\">"
elseif batstate == 1 then -- low yellow
color="<span color=\"yellow\">"
elseif batstate == 2 then -- critical red
color="<span color=\"red\">"
end
if batmin == "unknown" then
batmin = "?"
end
return(""..color..batpct.."% ["..batmin.."]".."</span>")
end
mybattmon = wibox.widget.textbox(battery_status())
my_battmon_timer=timer({timeout=30})
my_battmon_timer:connect_signal("timeout", function()
-- mytextbox.text = " " .. os.date() .. " "
mybattmon:set_markup(battery_status())
end)
my_battmon_timer:start()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment