From 94e7ed1beb1a69e896e322ed3c726a91ee60d88b Mon Sep 17 00:00:00 2001 From: "Adrian C. (anrxc)" Date: Tue, 9 Mar 2010 02:51:36 +0100 Subject: fs: rewritten, less prone to error --- fs.lua | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/fs.lua b/fs.lua index 4b2f598..f26038a 100644 --- a/fs.lua +++ b/fs.lua @@ -22,18 +22,19 @@ local unit = { ["mb"] = 1024, ["gb"] = 1024^2 } -- {{{ Filesystem widget type local function worker(format, nfs) - -- Fallback to listing only local file systems + -- Fallback to listing only local file-systems if nfs then nfs = "" else nfs = "--local" end - -- Get data from df - local f = io.popen("LANG=C df -kP " .. nfs) + -- Get (non-localized)data from df + local f = io.popen("LC_ALL=C df -kP " .. nfs) local fs_info = {} - for line in f:lines() do - local s, u, a, p, m = string.match(line, -- Match all at once (including NFS) - "[%w%p]+[%s]+([%d]+)[%s]+([%d]+)[%s]+([%d]+)[%s]+([%d]+)%%[%s]+([%w%p]+)$") + for line in f:lines() do -- Match: (size) (used)(avail)(use%) (mount) + local s = string.match(line, "^.-[%s]+([%d]+)") + local u,a,p = string.match(line, "([%d]+)[%s]+([%d]+)[%s]+([%d]+)%%") + local m = string.match(line, "%%[%s]([%p%w]+)") - if m ~= nil then + if u and m then -- Handle 1st line and broken regexp helpers.uformat(fs_info, m .. " size", s, unit) helpers.uformat(fs_info, m .. " used", u, unit) helpers.uformat(fs_info, m .. " avail", a, unit) -- cgit v1.2.3