diff options
Diffstat (limited to 'fs.lua')
-rw-r--r-- | fs.lua | 27 |
1 files changed, 19 insertions, 8 deletions
@@ -8,7 +8,10 @@ local tonumber = tonumber local io = { popen = io.popen } local setmetatable = setmetatable -local string = { match = string.match } +local string = { + match = string.match, + format = string.format +} -- }}} @@ -16,24 +19,32 @@ local string = { match = string.match } module("vicious.fs") +-- {{{ Helper functions +local function uformat(array, key, value) + array["{"..key.."_mb}"] = string.format("%.1f", value/1024) + array["{"..key.."_gb}"] = string.format("%.1f", value/1024/1024) + return array +end +-- }}} + -- {{{ Filesystem widget type local function worker(format, nfs) -- 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 -hP " .. nfs) + local f = io.popen("LANG=C df -kP " .. nfs) local fs_info = {} for line in f:lines() do if not string.match(line, "^Filesystem.*") then - local size, used, avail, usep, mount = string.match(line, -- Match all (network file systems too) - "^[%w%p]+[%s]+([%d%.]+)[%a]?[%s]+([%d%.]+)[%a]?[%s]+([%d%.]+)[%a]?[%s]+([%d]+)%%[%s]+([%w%p]+)$") + 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]+)$") - fs_info["{"..mount.." size}"] = tonumber(size) - fs_info["{"..mount.." used}"] = tonumber(used) - fs_info["{"..mount.." avail}"] = tonumber(avail) - fs_info["{"..mount.." usep}"] = tonumber(usep) + uformat(fs_info, m .. " size", s) + uformat(fs_info, m .. " used", u) + uformat(fs_info, m .. " avail", a) + fs_info["{" .. m .. " used_p}"] = tonumber(p) end end f:close() |