Update df.lua

-h for human readable, will show KB and MB
This commit is contained in:
istasi 2014-07-22 16:32:14 +02:00
parent 106e2fd197
commit dea42d852c

View File

@ -2,6 +2,17 @@ local fs = require("filesystem")
local shell = require("shell")
local args, options = shell.parse(...)
local f = function (m)
local s = {'','K','M','G'}
for _,f in ipairs (s) do
if m > 1024 then
m = m / 1024
else
return tostring (math.floor(m*100)/100) .. f .. 'B'
end
end
return tostring (math.floor(m*102400)/100) .. s[#s] .. 'B'
end
local mounts = {}
if #args == 0 then
@ -38,7 +49,11 @@ for path, proxy in pairs(mounts) do
percent = math.ceil(percent * 100) .. "%"
end
end
table.insert(result, {label, used, available, percent, path})
if options['h'] then
table.insert(result, {label, f(used), f(available), percent, path})
else
table.insert(result, {label, used, available, percent, path})
end
end