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 focused = require("awful.screen").focused
15 local wibox = require("wibox")
16 local naughty = require("naughty")
18 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(seconds, options, scr)
41 local cmd = (options and string.format("dfs %s", options)) or "dfs"
42 local ws = helpers.read_pipe(helpers.scripts_dir .. cmd):gsub("\n*$", "")
45 fs.notification_preset.screen = focused()
47 fs.notification_preset.screen = scr
50 fs_notification = naughty.notify({
51 preset = fs.notification_preset,
53 timeout = seconds or 5
58 local unit = { ["mb"] = 1024, ["gb"] = 1024^2 }
60 local function worker(args)
61 local args = args or {}
62 local timeout = args.timeout or 600
63 local partition = args.partition or "/"
64 local showpopup = args.showpopup or "on"
65 local notify = args.notify or "on"
66 local settings = args.settings or function() end
68 fs.followtag = args.followtag or false
69 fs.notification_preset = args.notification_preset or { fg = beautiful.fg_normal }
71 fs.widget = wibox.widget.textbox('')
73 helpers.set_map(partition, false)
78 local f = assert(io.popen("LC_ALL=C df -kP"))
80 for line in f:lines() do -- Match: (size) (used)(avail)(use%) (mount)
81 local s = string.match(line, "^.-[%s]([%d]+)")
82 local u,a,p = string.match(line, "([%d]+)[%D]+([%d]+)[%D]+([%d]+)%%")
83 local m = string.match(line, "%%[%s]([%p%w]+)")
85 if u and m then -- Handle 1st line and broken regexp
86 fs_info[m .. " size_mb"] = string.format("%.1f", tonumber(s) / unit["mb"])
87 fs_info[m .. " size_gb"] = string.format("%.1f", tonumber(s) / unit["gb"])
88 fs_info[m .. " used_mb"] = string.format("%.1f", tonumber(u) / unit["mb"])
89 fs_info[m .. " used_gb"] = string.format("%.1f", tonumber(u) / unit["gb"])
90 fs_info[m .. " used_p"] = tonumber(p)
91 fs_info[m .. " avail_p"] = 100 - tonumber(p)
97 fs_now.available = tonumber(fs_info[partition .. " avail_p"]) or 0
98 fs_now.size_mb = tonumber(fs_info[partition .. " size_mb"]) or 0
99 fs_now.size_gb = tonumber(fs_info[partition .. " size_gb"]) or 0
100 fs_now.used = tonumber(fs_info[partition .. " used_p"]) or 0
101 fs_now.used_mb = tonumber(fs_info[partition .. " used_mb"]) or 0
102 fs_now.used_gb = tonumber(fs_info[partition .. " used_gb"]) or 0
104 notification_preset = fs.notification_preset
108 if notify == "on" and fs_now.used >= 99 and not helpers.get_map(partition)
112 text = partition .. " ran out!\nmake some room",
117 helpers.set_map(partition, true)
119 helpers.set_map(partition, false)
123 if showpopup == "on" then
124 fs.widget:connect_signal('mouse::enter', function () fs.show(0) end)
125 fs.widget:connect_signal('mouse::leave', function () fs.hide() end)
128 helpers.newtimer(partition, timeout, update)
130 return setmetatable(fs, { __index = fs.widget })
133 return setmetatable(fs, { __call = function(_, ...) return worker(...) end })