All patches and comments are welcome. Please squash your changes to logical
commits before using git-format-patch and git-send-email to
patches@git.madduck.net.
If you'd read over the Git project's submission guidelines and adhered to them,
I'd be especially grateful.
4 Licensed under GNU General Public License v2
5 * (c) 2013, Luke Bonham
6 * (c) 2010, Adrian C. <anrxc@sysphere.org>
7 * (c) 2009, Lucas de Vries <lucas@glacicle.com>
11 local helpers = require("lain.helpers")
13 local beautiful = require("beautiful")
14 local wibox = require("wibox")
15 local naughty = require("naughty")
19 local string = { match = string.match,
20 format = string.format }
21 local tonumber = tonumber
23 local setmetatable = setmetatable
25 -- File system disk space usage
29 local notification = nil
30 notification_preset = { fg = beautiful.fg_normal }
33 if notification ~= nil then
34 naughty.destroy(notification)
39 function fs:show(t_out)
42 local f = io.popen(helpers.scripts_dir .. "dfs")
43 ws = f:read("*all"):gsub("\n*$", "")
46 notification = naughty.notify({
47 preset = notification_preset,
54 local unit = { ["mb"] = 1024, ["gb"] = 1024^2 }
56 local function worker(args)
57 local args = args or {}
58 local timeout = args.timeout or 600
59 local partition = args.partition or "/"
60 local settings = args.settings or function() end
62 fs.widget = wibox.widget.textbox('')
64 helpers.set_map("fs", false)
69 local f = io.popen("LC_ALL=C df -kP")
71 for line in f:lines() do -- Match: (size) (used)(avail)(use%) (mount)
72 local s = string.match(line, "^.-[%s]([%d]+)")
73 local u,a,p = string.match(line, "([%d]+)[%D]+([%d]+)[%D]+([%d]+)%%")
74 local m = string.match(line, "%%[%s]([%p%w]+)")
76 if u and m then -- Handle 1st line and broken regexp
77 fs_info[m .. " size_mb"] = string.format("%.1f", tonumber(s) / unit["mb"])
78 fs_info[m .. " size_gb"] = string.format("%.1f", tonumber(s) / unit["gb"])
79 fs_info[m .. " used_p"] = tonumber(p)
80 fs_info[m .. " avail_p"] = 100 - tonumber(p)
86 -- chosen partition easy stuff
87 -- you can however check whatever partition else
88 used = tonumber(fs_info[partition .. " used_p"])
89 available = tonumber(fs_info[partition .. " avail_p"])
90 size_mb = tonumber(fs_info[partition .. " size_mb"])
91 size_gb = tonumber(fs_info[partition .. " size_gb"])
96 if used >= 99 and not helpers.get_map("fs")
100 text = partition .. " ran out!\nmake some room",
105 helpers.set_map("fs", true)
107 helpers.set_map("fs", false)
111 helpers.newtimer(partition, timeout, fs.update)
113 widget:connect_signal('mouse::enter', function () fs:show(0) end)
114 widget:connect_signal('mouse::leave', function () fs:hide() end)
118 show = function(t_out)
124 return setmetatable(output, { __index = output.widget })
127 return setmetatable(fs, { __call = function(_, ...) return worker(...) end })