diff options
-rw-r--r-- | batat.lua | 9 | ||||
-rw-r--r-- | cpu.lua | 10 | ||||
-rw-r--r-- | cpuinf.lua | 13 | ||||
-rw-r--r-- | dio.lua | 10 | ||||
-rw-r--r-- | entropy.lua | 6 | ||||
-rw-r--r-- | fs.lua | 5 | ||||
-rw-r--r-- | gmail.lua | 10 | ||||
-rw-r--r-- | hddtemp.lua | 3 | ||||
-rw-r--r-- | load.lua | 5 | ||||
-rw-r--r-- | mdir.lua | 4 | ||||
-rw-r--r-- | mpd.lua | 6 | ||||
-rw-r--r-- | net.lua | 11 | ||||
-rw-r--r-- | pacman.lua | 3 | ||||
-rw-r--r-- | thermal.lua | 5 | ||||
-rw-r--r-- | uptime.lua | 13 | ||||
-rw-r--r-- | volume.lua | 8 |
16 files changed, 70 insertions, 51 deletions
@@ -7,6 +7,7 @@ local io = { popen = io.popen } local setmetatable = setmetatable local table = { insert = table.insert } +local string = { match = string.match } -- }}} @@ -30,12 +31,12 @@ local function worker(format) for line in f:lines() do -- Check if the battery is present - if line:match("^[%s]+Battery.*") then + if string.match(line, "^[%s]+Battery.*") then -- Store state and charge information - table.insert(battery_info, (battery_state[line:match("([%a]*),")] or "/")) - table.insert(battery_info, (line:match("([%d]?[%d]?[%d])%.") or "/")) + table.insert(battery_info, (battery_state[string.match(line, "([%a]*),")] or "/")) + table.insert(battery_info, (string.match(line, "([%d]?[%d]?[%d])%.") or "/")) -- Store remaining time information - table.insert(battery_info, (line:match("%%,%s(.*)") or "/")) + table.insert(battery_info, (string.match(line, "%%,%s(.*)") or "/")) else return {"/", "/", "/"} end @@ -10,6 +10,10 @@ local io = { open = io.open } local setmetatable = setmetatable local math = { floor = math.floor } local table = { insert = table.insert } +local string = { + find = string.find, + gmatch = string.gmatch +} -- }}} @@ -29,13 +33,13 @@ local function worker(format) local cpu_lines = {} for line in f:lines() do - if line:find("^cpu") then + if string.find(line, "^cpu") then if #cpu_lines < 1 then cpuid = 1 else cpuid = #cpu_lines + 1 end cpu_lines[cpuid] = {} - for match in line:gmatch("[%s]+([%d]+)") do - table.insert(cpu_lines[cpuid], match) + for i in string.gmatch(line, "[%s]+([%d]+)") do + table.insert(cpu_lines[cpuid], i) end end end @@ -7,6 +7,7 @@ local tonumber = tonumber local io = { open = io.open } local setmetatable = setmetatable +local string = { match = string.match } -- }}} @@ -22,14 +23,14 @@ local function worker(format) local cpu_info = {} for line in f:lines() do - if line:match("^processor.*") then - cpu_id = line:match("([%d]+)") - elseif line:match("^cpu MHz.*") then - local cpu_speed = line:match("([%d]+)%.") + if string.match(line, "^processor.*") then + cpu_id = string.match(line, "([%d]+)") + elseif string.match(line, "^cpu MHz.*") then + local cpu_speed = string.match(line, "([%d]+)%.") cpu_info["{cpu"..cpu_id.." mhz}"] = cpu_speed cpu_info["{cpu"..cpu_id.." ghz}"] = tonumber(cpu_speed) / 1000 - elseif line:match("^cache size.*") then - local cpu_cache = line:match("([%d]+)[%s]KB") + elseif string.match(line, "^cache size.*") then + local cpu_cache = string.match(line, "([%d]+)[%s]KB") cpu_info["{cpu"..cpu_id.." kb}"] = cpu_cache cpu_info["{cpu"..cpu_id.." mb}"] = tonumber(cpu_cache) / 1024 end @@ -10,6 +10,10 @@ local io = { open = io.open } local setmetatable = setmetatable local math = { floor = math.floor } local table = { insert = table.insert } +local string = { + match = string.match, + gmatch = string.gmatch +} -- }}} @@ -28,14 +32,14 @@ local function worker(format, disk) local disk_lines = {} for line in f:lines() do - if line:match("("..disk..")%s") then + if string.match(line, "("..disk..")%s") then -- Todo: find a way to do this - --for stat in line:gmatch("%s([%d]+)") do + --for stat in string.gmatch(line, "%s([%d]+)") do -- table.insert(disk_lines, stat) --end -- -- Skip first two matches - local stat = line:gmatch("%s([%d]+)") + local stat = string.gmatch(line, "%s([%d]+)") stat() stat() -- Store the rest diff --git a/entropy.lua b/entropy.lua index ca7ee85..d36a8a9 100644 --- a/entropy.lua +++ b/entropy.lua @@ -21,13 +21,13 @@ local function worker(format, poolsize) -- Get available entropy local f = io.open("/proc/sys/kernel/random/entropy_avail") - local ent_avail = f:read("*line") + local ent = f:read("*line") f:close() -- Calculate percentage - local ent_avail_percent = math.ceil(ent_avail * 100 / poolsize) + local ent_percent = math.ceil(ent * 100 / poolsize) - return {ent_avail, ent_avail_percent} + return {ent, ent_percent} end -- }}} @@ -7,6 +7,7 @@ -- {{{ Grab environment local io = { popen = io.popen } local setmetatable = setmetatable +local string = { match = string.match } -- }}} @@ -24,10 +25,10 @@ local function worker(format, nfs) local fs_info = {} for line in f:lines() do - if not line:match("^Filesystem.*") then + if not string.match(line, "^Filesystem.*") then local size, used, avail, usep, mount = -- Match all at once, including network file systems - line:match("^[%w%p]+[%s]+([%d%.]+)[%a]?[%s]+([%d%.]+)[%a]?[%s]+([%d%.]+)[%a]?[%s]+([%d]+)%%[%s]+([%w%p]+)$") + string.match(line, "^[%w%p]+[%s]+([%d%.]+)[%a]?[%s]+([%d%.]+)[%a]?[%s]+([%d%.]+)[%a]?[%s]+([%d]+)%%[%s]+([%w%p]+)$") fs_info["{"..mount.." size}"] = size fs_info["{"..mount.." used}"] = used @@ -6,6 +6,7 @@ -- {{{ Grab environment local io = { popen = io.popen } local setmetatable = setmetatable +local string = { match = string.match } local helpers = require("vicious.helpers") -- }}} @@ -15,7 +16,7 @@ module("vicious.gmail") -- User data -local user = "" -- Todo +local user = "" -- Todo: local pass = "" -- * find a safer storage -- {{{ Gmail widget type @@ -32,10 +33,11 @@ local function worker(format, feed) -- Could be huge don't read it all at once, info we are after is at the top for line in f:lines() do - mail["{count}"] = line:match("<fullcount>([%d]+)</fullcount>") or mail["{count}"] + mail["{count}"] = -- Count comes before messages and matches at least 0 + string.match(line, "<fullcount>([%d]+)</fullcount>") or mail["{count}"] -- Find subject tags - local title = line:match("<title>(.*)</title>") + local title = string.match(line, "<title>(.*)</title>") -- If the subject changed then break out of the loop if title ~= nil and -- Todo: find a better way to deal with 1st title title ~= "Gmail - Label 'unread' for "..user.."@gmail.com" then @@ -43,8 +45,6 @@ local function worker(format, feed) title = helpers.escape(title) -- Don't abuse the wibox, truncate, then store mail["{subject}"] = helpers.truncate(title, 22) - -- By this point we have the count, it comes before - -- messages and always matches, at least 0 break end end diff --git a/hddtemp.lua b/hddtemp.lua index 7bdb764..9e35b5f 100644 --- a/hddtemp.lua +++ b/hddtemp.lua @@ -6,6 +6,7 @@ -- {{{ Grab environment local io = { popen = io.popen } local setmetatable = setmetatable +local string = { match = string.match } -- }}} @@ -23,7 +24,7 @@ local function worker(format, port) local hdd_temp = {} for line in f:lines() do - local disk, temp = line:match("|([%/%a]+)|.*|([%d]+)|[CF]+|") + local disk, temp = string.match(line, "|([%/%a]+)|.*|([%d]+)|[CF]+|") if disk ~= nil and temp ~= nil then hdd_temp["{"..disk.."}"] = temp @@ -6,6 +6,7 @@ -- {{{ Grab environment local io = { open = io.open } local setmetatable = setmetatable +local string = { match = string.match } -- }}} @@ -15,12 +16,12 @@ module("vicious.load") -- {{{ Load widget type local function worker(format) - -- Get load averages local f = io.open('/proc/loadavg') local line = f:read("*line") f:close() - local l1, l5, l15 = line:match("([%d]*%.[%d]*)%s([%d]*%.[%d]*)%s([%d]*%.[%d]*)") + local l1, l5, l15 = -- Get load averages for past 1, 5 and 15 minutes + string.match(line, "([%d]*%.[%d]*)%s([%d]*%.[%d]*)%s([%d]*%.[%d]*)") return {l1, l5, l15} end @@ -20,12 +20,12 @@ local function worker(format, mdir) local count = { new = 0, cur = 0 } -- Recursively find new messages - local f = io.popen("find " .. mdir .. " -type f -wholename '*/new/*'") + local f = io.popen("find "..mdir.." -type f -wholename '*/new/*'") for line in f:lines() do count.new = count.new + 1 end f:close() -- Recursively find "old" messages lacking the Seen flag - local f = io.popen("find " .. mdir .. " -type f -regex '.*/cur/.*2,[^S]*$'") + local f = io.popen("find "..mdir.." -type f -regex '.*/cur/.*2,[^S]*$'") for line in f:lines() do count.cur = count.cur + 1 end f:close() @@ -8,6 +8,7 @@ local io = { popen = io.popen } local setmetatable = setmetatable local helpers = require("vicious.helpers") +local string = { find = string.find } -- }}} @@ -23,7 +24,8 @@ local function worker(format) f:close() -- Check if it's stopped, off or not installed - if np == nil or (np:find("MPD_HOST") or np:find("volume:")) then + if np == nil + or (string.find(np, "MPD_HOST") or string.find(np, "volume:")) then return {"Stopped"} end @@ -31,7 +33,7 @@ local function worker(format) local nowplaying = helpers.escape(np) -- Don't abuse the wibox, truncate - local nowplaying = helpers.truncate(nowplaying, 30) + nowplaying = helpers.truncate(nowplaying, 30) return {nowplaying} end @@ -10,6 +10,7 @@ local os = { time = os.time } local io = { open = io.open } local setmetatable = setmetatable local math = { floor = math.floor } +local string = { match = string.match } -- }}} @@ -28,12 +29,12 @@ local function worker(format) for line in f:lines() do -- Match wmaster0 as well as rt0 (multiple leading spaces) - if line:match("^[%s]?[%s]?[%s]?[%s]?[%w]+:") then - local name = line:match("^[%s]?[%s]?[%s]?[%s]?([%w]+):") + if string.match(line, "^[%s]?[%s]?[%s]?[%s]?[%w]+:") then + local name = string.match(line, "^[%s]?[%s]?[%s]?[%s]?([%w]+):") -- Received bytes, first value after the name - local recv = tonumber(line:match(":[%s]*([%d]+)")) - -- Transmited bytes, 7 fields from end of the line - local send = tonumber(line:match("([%d]+)%s+%d+%s+%d+%s+%d+%s+%d+%s+%d+%s+%d+%s+%d$")) + local recv = tonumber(string.match(line, ":[%s]*([%d]+)")) + local send = -- Transmited bytes, 7 fields from end of the line + tonumber(string.match(line, "([%d]+)%s+%d+%s+%d+%s+%d+%s+%d+%s+%d+%s+%d+%s+%d$")) args["{"..name.." rx_b}"] = math.floor(recv*10)/10 args["{"..name.." tx_b}"] = math.floor(send*10)/10 @@ -7,6 +7,7 @@ local tonumber = tonumber local io = { popen = io.popen } local setmetatable = setmetatable +--local string = { match = string.match } -- }}} @@ -24,7 +25,7 @@ local function worker(format) for line in f:lines() do -- Pacman 3.2 provides the number of available updates - --updates = line:match("^Targets[%s]%(([%d]+)%)") or 0 + --updates = string.match(line, "^Targets[%s]%(([%d]+)%)") or 0 ---- If the count changed then break out of the loop --if tonumber(updates) > 0 then -- break diff --git a/thermal.lua b/thermal.lua index ab7ef89..1697eb0 100644 --- a/thermal.lua +++ b/thermal.lua @@ -6,6 +6,7 @@ -- {{{ Grab environment local io = { open = io.open } local setmetatable = setmetatable +local string = { match = string.match } -- }}} @@ -16,13 +17,13 @@ module("vicious.thermal") -- {{{ Thermal widget type local function worker(format, thermal_zone) -- Get an ACPI thermal zone - local f = io.open("/proc/acpi/thermal_zone/" .. thermal_zone .. "/temperature") + local f = io.open("/proc/acpi/thermal_zone/"..thermal_zone.."/temperature") -- Handler for incompetent users if not f then return {"N/A"} end local line = f:read("*line") f:close() - local temperature = line:match("[%d]?[%d]?[%d]") + local temperature = string.match(line, "[%d]?[%d]?[%d]") return {temperature} end @@ -9,6 +9,7 @@ local tonumber = tonumber local io = { open = io.open } local setmetatable = setmetatable local math = { floor = math.floor } +local string = { match = string.match } -- }}} @@ -23,13 +24,13 @@ local function worker(format) local line = f:read("*line") f:close() - local total_uptime = math.floor(tonumber(line:match("[%d%.]+"))) - local uptime_days = math.floor(total_uptime / (3600 * 24)) - local uptime_hours = math.floor((total_uptime % (3600 * 24)) / 3600) - local uptime_minutes = math.floor(((total_uptime % (3600 * 24)) % 3600) / 60) - local uptime_seconds = math.floor(((total_uptime % (3600 * 24)) % 3600) % 60) + local up_t = math.floor(tonumber(string.match(line, "[%d%.]+"))) + local up_d = math.floor(up_t / (3600 * 24)) + local up_h = math.floor((up_t % (3600 * 24)) / 3600) + local up_m = math.floor(((up_t % (3600 * 24)) % 3600) / 60) + local up_s = math.floor(((up_t % (3600 * 24)) % 3600) % 60) - return {total_uptime, uptime_days, uptime_hours, uptime_minutes, uptime_seconds} + return {up_t, up_d, up_h, up_m, up_s} end -- }}} @@ -24,13 +24,13 @@ local function worker(format, channel) local mixer = f:read("*all") f:close() - local volume_level = string.match(mixer, "([%d]?[%d]?[%d])%%") + local vol = string.match(mixer, "([%d]?[%d]?[%d])%%") -- If muted return 0 (not "Mute") so we dont break progressbars - if string.find(mixer, "%[off%]") or volume_level == nil then - volume_level = 0 + if string.find(mixer, "%[off%]") or vol == nil then + vol = 0 end - return {volume_level} + return {vol} end -- }}} |