- fs_info, fs_now = {}, {}
- helpers.async({ shell, "-c", "/usr/bin/env LC_ALL=C df -k --output=target,size,used,avail,pcent" }, function(f)
- for line in string.gmatch(f, "\n[^\n]+") do
- local m,s,u,a,p = string.match(line, "(/.-%s).-(%d+).-(%d+).-(%d+).-([%d]+)%%")
- m = m:gsub(" ", "") -- clean target from any whitespace
-
- fs_info[m .. " size_mb"] = string.format("%.1f", tonumber(s) / fs.unit["mb"])
- fs_info[m .. " size_gb"] = string.format("%.1f", tonumber(s) / fs.unit["gb"])
- fs_info[m .. " used_mb"] = string.format("%.1f", tonumber(u) / fs.unit["mb"])
- fs_info[m .. " used_gb"] = string.format("%.1f", tonumber(u) / fs.unit["gb"])
- fs_info[m .. " used_p"] = p
- fs_info[m .. " avail_mb"] = string.format("%.1f", tonumber(a) / fs.unit["mb"])
- fs_info[m .. " avail_gb"] = string.format("%.1f", tonumber(a) / fs.unit["gb"])
- fs_info[m .. " avail_p"] = string.format("%d", 100 - tonumber(p))
+ local notifytable = { [1] = string.format("%-10s %-5s %s\t%s\t\n", "path", "used", "free", "size") }
+ local pathlen = 10
+ local maxpathidx = 1
+ fs_now = {}
+
+ for _, mount in ipairs(Gio.unix_mounts_get()) do
+ local path = Gio.unix_mount_get_mount_path(mount)
+ local root = Gio.File.new_for_path(path)
+ local info = root:query_filesystem_info(query)
+
+ if info then
+ local size = info:get_attribute_uint64(query_size)
+ local used = info:get_attribute_uint64(query_used)
+ local free = info:get_attribute_uint64(query_free)
+
+ if size > 0 then
+ local units = math.floor(math.log(size)/math.log(1024))
+
+ fs_now[path] = {
+ units = fs.units[units],
+ percentage = math.floor(100 * used / size), -- used percentage
+ size = size / math.pow(1024, math.floor(units)),
+ used = used / math.pow(1024, math.floor(units)),
+ free = free / math.pow(1024, math.floor(units))
+ }
+
+ if fs_now[path].percentage > 0 then -- don't notify unused file systems
+ notifytable[#notifytable+1] = string.format("\n%-10s %-3s\t%.2f\t%.2f\t%s", path,
+ math.floor(fs_now[path].percentage) .. "%", fs_now[path].free, fs_now[path].size,
+ fs_now[path].units)
+
+ if #path > pathlen then
+ pathlen = #path
+ maxpathidx = #notifytable
+ end
+ end
+ end