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 }
22 >>>>>>> upstream/master
23 local string = { match = string.match,
24 format = string.format }
25 local tonumber = tonumber
27 local setmetatable = setmetatable
29 -- File system disk space usage
34 local notification = nil
35 fs_notification_preset = { fg = beautiful.fg_normal }
38 if notification ~= nil then
39 naughty.destroy(notification)
42 local fs_notification = nil
45 if fs_notification ~= nil then
46 naughty.destroy(fs_notification)
48 >>>>>>> upstream/master
52 function fs:show(t_out)
56 local f = io.popen(helpers.scripts_dir .. "dfs")
57 ws = f:read("*a"):gsub("\n*$", "")
60 notification = naughty.notify({
61 preset = fs_notification_preset,
65 local ws = helpers.read_pipe(helpers.scripts_dir .. "dfs"):gsub("\n*$", "")
67 if fs.followmouse then
68 fs.notification_preset.screen = mouse.screen
71 fs_notification = naughty.notify({
72 preset = fs.notification_preset,
75 >>>>>>> upstream/master
80 local unit = { ["mb"] = 1024, ["gb"] = 1024^2 }
82 local function worker(args)
84 local args = args or {}
85 local timeout = args.timeout or 600
86 local partition = args.partition or "/"
87 local settings = args.settings or function() end
89 local args = args or {}
90 local timeout = args.timeout or 600
91 local partition = args.partition or "/"
92 local settings = args.settings or function() end
94 fs.followmouse = args.followmouse or false
95 fs.notification_preset = args.notification_preset or { fg = beautiful.fg_normal }
96 >>>>>>> upstream/master
98 fs.widget = wibox.widget.textbox('')
100 helpers.set_map(partition, false)
105 local f = assert(io.popen("LC_ALL=C df -kP"))
107 for line in f:lines() do -- Match: (size) (used)(avail)(use%) (mount)
108 local s = string.match(line, "^.-[%s]([%d]+)")
109 local u,a,p = string.match(line, "([%d]+)[%D]+([%d]+)[%D]+([%d]+)%%")
110 local m = string.match(line, "%%[%s]([%p%w]+)")
112 if u and m then -- Handle 1st line and broken regexp
113 fs_info[m .. " size_mb"] = string.format("%.1f", tonumber(s) / unit["mb"])
114 fs_info[m .. " size_gb"] = string.format("%.1f", tonumber(s) / unit["gb"])
115 fs_info[m .. " used_p"] = tonumber(p)
116 fs_info[m .. " avail_p"] = 100 - tonumber(p)
122 fs_now.used = tonumber(fs_info[partition .. " used_p"]) or 0
123 fs_now.available = tonumber(fs_info[partition .. " avail_p"]) or 0
124 fs_now.size_mb = tonumber(fs_info[partition .. " size_mb"]) or 0
125 fs_now.size_gb = tonumber(fs_info[partition .. " size_gb"]) or 0
130 if fs_now.used >= 99 and not helpers.get_map(partition)
134 text = partition .. " ran out!\nmake some room",
139 helpers.set_map(partition, true)
141 helpers.set_map(partition, false)
145 fs.widget:connect_signal('mouse::enter', function () fs:show(0) end)
146 fs.widget:connect_signal('mouse::leave', function () fs:hide() end)
148 helpers.newtimer(partition, timeout, update)
150 return setmetatable(fs, { __index = fs.widget })
153 return setmetatable(fs, { __call = function(_, ...) return worker(...) end })