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
9 local helpers = require("lain.helpers")
11 local shell = require("awful.util").shell
12 local beautiful = require("beautiful")
13 local focused = require("awful.screen").focused
14 local wibox = require("wibox")
15 local naughty = require("naughty")
18 local tonumber = tonumber
20 local setmetatable = setmetatable
22 -- File system disk space usage
27 fs.unit = { ["mb"] = 1024, ["gb"] = 1024^2 }
30 naughty.destroy(fs.notification)
34 function fs.show(seconds, scr)
38 fs.notification_preset.screen = focused()
40 fs.notification_preset.screen = scr
43 local cmd = (fs.options and string.format("dfs %s", fs.options)) or "dfs"
45 helpers.async(helpers.scripts_dir .. cmd, function(ws)
46 fs.notification = naughty.notify({
47 preset = fs.notification_preset,
48 text = ws:gsub("\n*$", ""),
49 timeout = seconds or 5,
54 local function worker(args)
55 local args = args or {}
56 local timeout = args.timeout or 600
57 local partition = args.partition or "/"
58 local showpopup = args.showpopup or "on"
59 local notify = args.notify or "on"
60 local settings = args.settings or function() end
62 fs.options = args.options
63 fs.followtag = args.followtag or false
64 fs.notification_preset = args.notification_preset or { fg = beautiful.fg_normal }
66 fs.widget = wibox.widget.textbox()
68 helpers.set_map(partition, false)
72 fs_info, fs_now = {}, {}
73 helpers.async(string.format("%s -c 'LC_ALL=C df -k --output=target,size,used,avail,pcent'", shell), function(f)
74 for line in string.gmatch(f, "\n[^\n]+") do
75 local m,s,u,a,p = string.match(line, "(/.-%s).-(%d+).-(%d+).-(%d+).-([%d]+)%%")
76 m = m:gsub(" ", "") -- clean target from any whitespace
78 fs_info[m .. " size_mb"] = string.format("%.1f", tonumber(s) / fs.unit["mb"])
79 fs_info[m .. " size_gb"] = string.format("%.1f", tonumber(s) / fs.unit["gb"])
80 fs_info[m .. " used_mb"] = string.format("%.1f", tonumber(u) / fs.unit["mb"])
81 fs_info[m .. " used_gb"] = string.format("%.1f", tonumber(u) / fs.unit["gb"])
82 fs_info[m .. " used_p"] = p
83 fs_info[m .. " avail_mb"] = string.format("%.1f", tonumber(a) / fs.unit["mb"])
84 fs_info[m .. " avail_gb"] = string.format("%.1f", tonumber(a) / fs.unit["gb"])
85 fs_info[m .. " avail_p"] = string.format("%d", 100 - tonumber(p))
88 fs_now.size_mb = fs_info[partition .. " size_mb"] or "N/A"
89 fs_now.size_gb = fs_info[partition .. " size_gb"] or "N/A"
90 fs_now.used = fs_info[partition .. " used_p"] or "N/A"
91 fs_now.used_mb = fs_info[partition .. " used_mb"] or "N/A"
92 fs_now.used_gb = fs_info[partition .. " used_gb"] or "N/A"
93 fs_now.available = fs_info[partition .. " avail_p"] or "N/A"
94 fs_now.available_mb = fs_info[partition .. " avail_mb"] or "N/A"
95 fs_now.available_gb = fs_info[partition .. " avail_gb"] or "N/A"
97 notification_preset = fs.notification_preset
101 if notify == "on" and tonumber(fs_now.used) >= 99 and not helpers.get_map(partition) then
104 text = partition .. " is empty!",
109 helpers.set_map(partition, true)
111 helpers.set_map(partition, false)
116 if showpopup == "on" then
117 fs.widget:connect_signal('mouse::enter', function () fs.show(0) end)
118 fs.widget:connect_signal('mouse::leave', function () fs.hide() end)
121 helpers.newtimer(partition, timeout, update)
123 return setmetatable(fs, { __index = fs.widget })
126 return setmetatable(fs, { __call = function(_, ...) return worker(...) end })