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")
17 local io = { popen = io.popen }
20 local string = { match = string.match,
21 format = string.format }
22 local tonumber = tonumber
24 local setmetatable = setmetatable
26 -- File system disk space usage
29 local fs_notification = nil
32 if fs_notification ~= nil then
33 naughty.destroy(fs_notification)
38 function fs:show(t_out)
41 local f = io.popen(helpers.scripts_dir .. "dfs")
42 ws = f:read("*all"):gsub("\n*$", "")
45 if fs.followmouse then
46 fs.notification_preset.screen = mouse.screen
49 fs_notification = naughty.notify({
50 preset = fs.notification_preset,
57 local unit = { ["mb"] = 1024, ["gb"] = 1024^2 }
59 local function worker(args)
60 local args = args or {}
61 local timeout = args.timeout or 600
62 local partition = args.partition or "/"
63 local settings = args.settings or function() end
65 fs.followmouse = args.followmouse or false
66 fs.notification_preset = args.notification_preset or { fg = beautiful.fg_normal }
68 fs.widget = wibox.widget.textbox('')
70 helpers.set_map(partition, false)
75 local f = assert(io.popen("LC_ALL=C df -kP"))
77 for line in f:lines() do -- Match: (size) (used)(avail)(use%) (mount)
78 local s = string.match(line, "^.-[%s]([%d]+)")
79 local u,a,p = string.match(line, "([%d]+)[%D]+([%d]+)[%D]+([%d]+)%%")
80 local m = string.match(line, "%%[%s]([%p%w]+)")
82 if u and m then -- Handle 1st line and broken regexp
83 fs_info[m .. " size_mb"] = string.format("%.1f", tonumber(s) / unit["mb"])
84 fs_info[m .. " size_gb"] = string.format("%.1f", tonumber(s) / unit["gb"])
85 fs_info[m .. " used_p"] = tonumber(p)
86 fs_info[m .. " avail_p"] = 100 - tonumber(p)
92 fs_now.used = tonumber(fs_info[partition .. " used_p"]) or 0
93 fs_now.available = tonumber(fs_info[partition .. " avail_p"]) or 0
94 fs_now.size_mb = tonumber(fs_info[partition .. " size_mb"]) or 0
95 fs_now.size_gb = tonumber(fs_info[partition .. " size_gb"]) or 0
100 if fs_now.used >= 99 and not helpers.get_map(partition)
104 text = partition .. " ran out!\nmake some room",
109 helpers.set_map(partition, true)
111 helpers.set_map(partition, false)
115 fs.widget:connect_signal('mouse::enter', function () fs:show(0) end)
116 fs.widget:connect_signal('mouse::leave', function () fs:hide() end)
118 helpers.newtimer(partition, timeout, update)
120 return setmetatable(fs, { __index = fs.widget })
123 return setmetatable(fs, { __call = function(_, ...) return worker(...) end })