local wibox = require("wibox") local widgets = require("util.widgets") function linux_ram_usage(widget) -- read meminfo local meminfof = io.open("/proc/meminfo") local total = meminfof:read():match("%d+") local free = meminfof:read():match("%d+") meminfof:read() -- memavailable not used local buffers = meminfof:read():match("%d+") local cached = meminfof:read():match("%d+") meminfof:close() -- calc if total == nil then return end local used = (total - free - buffers - cached) * 100 / total widget:set_text(math.floor(used)) end -- return correct widget for os if osname == "Linux" then return widgets.watchfn(linux_ram_usage, 5) end return wibox.widget.textbox("unsupported os")