From 3a8967e4192323980c89e6f200e60c191a125538 Mon Sep 17 00:00:00 2001 From: Reiner Herrmann Date: Sat, 31 Jan 2015 23:37:11 +0100 Subject: awesome: calculate cpu string dynamically --- awesome/rc.lua | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'awesome/rc.lua') diff --git a/awesome/rc.lua b/awesome/rc.lua index 178bbcb..72f421a 100644 --- a/awesome/rc.lua +++ b/awesome/rc.lua @@ -140,8 +140,26 @@ for bat = 0, 1 do end end +function cpu_string() + local f = io.open("/proc/cpuinfo", "r") + local n = 2 + local result = " CPU:$2%" + if f then + f:read() -- skip first line/processor + for line in f:lines() do + m = string.match(line, "processor\t*: %d+") + if m then + n = n + 1 + result = result .. "/$" .. n .. "%" + end + end + f:close() + end + return result .. " " +end + cpuwidget = widget({ type = 'textbox', name = 'cpuwidget', align = 'right' }) -vicious.register(cpuwidget, vicious.widgets.cpu, ' CPU:$2%/$3%/$4%/$5% ', 2) +vicious.register(cpuwidget, vicious.widgets.cpu, cpu_string(), 2) -- Create a systray mysystray = widget({ type = "systray" }) -- cgit v1.2.3