Skip to content

Instantly share code, notes, and snippets.

@ShadOoW
Last active December 19, 2015 17:18
Show Gist options
  • Save ShadOoW/1ec33a0d82a08eee99c5 to your computer and use it in GitHub Desktop.
Save ShadOoW/1ec33a0d82a08eee99c5 to your computer and use it in GitHub Desktop.
battery_icons = {'', '', '', '', ''}
-- Create a battery widgets
batterywidget = wibox.widget.textbox()
batterywidget:set_text(" Battery | ")
batterywidgettimer = timer({ timeout = 5 })
batterywidgettimer:connect_signal("timeout",
function()
fh = assert(io.popen("acpi | cut -d, -f 2 -", "r"))
local num = tonumber(string.sub(fh:read("*l"),1,-2))
fh:close()
fh = assert(io.popen("acpi | cut -d ' ' -f 3 -", "r"))
local status = fh:read("*l")
fh:close()
if status == "Charging," then
status = "+"
else
status = "-"
end
local icon = ""
if num < 15 then
icon = battery_icons[1]
elseif num < 40 then
icon = battery_icons[2]
elseif num < 70 then
icon = battery_icons[3]
elseif num < 85 then
icon = battery_icons[4]
else
icon = battery_icons[5]
end
if num < 15 and status == '-' then
naughty.notify({text="Battery is Low"})
batterywidget:set_markup(icon .. ' <span color="#ff6666">' .. status .. num .. '%</span> ' .. " | ")
else
batterywidget:set_markup(icon .. ' <span color="#34bb99">' .. status .. num .. '%</span> ' .. " | ")
end
end
)
batterywidgettimer:start()
batterywidgettimer:emit_signal("timeout")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment