+ mytimebox.text = " " .. os.date() .. " "
+end)
+
+-- Hook called every sixty seconds
+function hook_battery()
+ mybatterybox.text = " " .. get_acpibatt() .. " "
+end
+
+-- {{{ Statusbar battery
+--
+function get_acpibatt()
+
+ local f = io.popen('acpi -b', 'r')
+ if not f then
+ return "acpi -b failed"
+ end
+
+ local s = f:read('*l')
+ f:close()
+ if not s then
+ return '-';
+ end
+
+ -- Battery 0: Discharging, 89%, 00:02:14 remaining
+ -- Battery 0: Charging, 58%, 00:02:14 until charged
+ -- Battery 0: Full, 100%
+ -- so find the first bit first and then go look for the time
+ local st, en, status, percent = string.find(s, '%a+%s%d:%s(%a+),%s(%d+%%)');
+ local st, en, time = string.find(s, ',%s(%d+:%d+:%d+)%s%a+', en);
+
+ if not status or not percent then -- time can be empty if we're full
+ return "couldn't parse line " .. s
+ end
+
+ if not time then
+ return percent
+ end
+
+ if status == 'Charging' then
+ status = 'c';
+ elseif status == 'Discarching' then
+ status = 'd';
+ else
+ status = '-';
+ end
+
+ return percent; -- .. ' (' .. status .. ')'; -- .. ' ' .. time .. ' left';
+end
+-- }}}
+
+--{{{ batt hook
+local function get_bat()
+ local a = io.open("/sys/class/power_supply/BAT1/charge_full")
+ for line in a:lines() do
+ full = line
+ end
+ a:close()
+ local b = io.open("/sys/class/power_supply/BAT1/charge_now")
+ for line in b:lines() do
+ now = line
+ end
+ b:close()
+ batt=math.floor(now*100/full)
+ batterywidget:bar_data_add("bat",batt )