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
27 local fs = { notification_preset = {} }
28 local notification = nil
31 if notification ~= nil then
32 naughty.destroy(notification)
37 function fs:show(t_out)
40 local f = io.popen(helpers.scripts_dir .. "dfs")
41 ws = f:read("*all"):gsub("\n*$", "")
44 notification = naughty.notify({
45 preset = fs.notification_preset,
52 local unit = { ["mb"] = 1024, ["gb"] = 1024^2 }
54 local function worker(args)
55 local args = args or {}
56 local partition = args.partition or "/"
57 local timeout = args.timeout or 600
58 local settings = args.settings or function() end
60 widget = wibox.widget.textbox('')
62 helpers.set_map("fs", false)
67 local f = io.popen("LC_ALL=C df -kP")
69 for line in f:lines() do -- Match: (size) (used)(avail)(use%) (mount)
70 local s = string.match(line, "^.-[%s]([%d]+)")
71 local u,a,p = string.match(line, "([%d]+)[%D]+([%d]+)[%D]+([%d]+)%%")
72 local m = string.match(line, "%%[%s]([%p%w]+)")
74 if u and m then -- Handle 1st line and broken regexp
75 fs_info[m .. " size_mb"] = string.format("%.1f", tonumber(s) / unit["mb"])
76 fs_info[m .. " size_gb"] = string.format("%.1f", tonumber(s) / unit["gb"])
77 fs_info[m .. " used_p"] = tonumber(p)
78 fs_info[m .. " avail_p"] = 100 - tonumber(p)
84 -- chosen partition easy stuff
85 -- you can however check whatever partition else
86 used = fs_info[partition .. " used_p"]
87 available = fs_info[partition .. " avail_p"]
88 size_mb = fs_info[partition .. " size_mb"]
89 size_gb = fs_info[partition .. " size_gb"]
91 notification_preset = { fg = beautiful.fg_normal }
95 fs.notification_preset = notification_preset
97 if used >= 99 and not helpers.get_map("fs")
101 text = partition .. " ran out!\nmake some room",
106 helpers.set_map("fs", true)
108 helpers.set_map("fs", false)
112 helpers.newtimer("fs " .. partition, timeout, update)
114 widget:connect_signal('mouse::enter', function () fs:show(0) end)
115 widget:connect_signal('mouse::leave', function () fs:hide() end)
119 show = function(t_out)
125 return setmetatable(output, { __index = output.widget })
128 return setmetatable(fs, { __call = function(_, ...) return worker(...) end })