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")
10 local shell = require("awful.util").shell
11 local focused = require("awful.screen").focused
12 local wibox = require("wibox")
13 local naughty = require("naughty")
15 local tonumber = tonumber
17 -- File system disk space usage
20 local function factory(args)
21 local fs = { unit = { ["mb"] = 1024, ["gb"] = 1024^2 }, widget = wibox.widget.textbox() }
24 if not fs.notification then return end
25 naughty.destroy(fs.notification)
29 function fs.show(seconds, scr)
34 fs.notification_preset.screen = focused()
36 fs.notification_preset.screen = scr or 1
39 fs.notification = naughty.notify({
40 preset = fs.notification_preset,
41 timeout = seconds or 5
45 local args = args or {}
46 local timeout = args.timeout or 600
47 local partition = args.partition or "/"
48 local showpopup = args.showpopup or "on"
49 local notify = args.notify or "on"
50 local settings = args.settings or function() end
52 fs.options = args.options
53 fs.followtag = args.followtag or false
54 fs.notification_preset = args.notification_preset
56 if not fs.notification_preset then
57 fs.notification_preset = {
58 font = "Monospace 10",
64 helpers.set_map(partition, false)
67 fs_info, fs_now = {}, {}
68 helpers.async({ shell, "-c", "/usr/bin/env LC_ALL=C df -k --output=target,size,used,avail,pcent" }, function(f)
69 for line in string.gmatch(f, "\n[^\n]+") do
70 local m,s,u,a,p = string.match(line, "(/.-%s).-(%d+).-(%d+).-(%d+).-([%d]+)%%")
71 m = m:gsub(" ", "") -- clean target from any whitespace
73 fs_info[m .. " size_mb"] = string.format("%.1f", tonumber(s) / fs.unit["mb"])
74 fs_info[m .. " size_gb"] = string.format("%.1f", tonumber(s) / fs.unit["gb"])
75 fs_info[m .. " used_mb"] = string.format("%.1f", tonumber(u) / fs.unit["mb"])
76 fs_info[m .. " used_gb"] = string.format("%.1f", tonumber(u) / fs.unit["gb"])
77 fs_info[m .. " used_p"] = p
78 fs_info[m .. " avail_mb"] = string.format("%.1f", tonumber(a) / fs.unit["mb"])
79 fs_info[m .. " avail_gb"] = string.format("%.1f", tonumber(a) / fs.unit["gb"])
80 fs_info[m .. " avail_p"] = string.format("%d", 100 - tonumber(p))
83 fs_now.size_mb = fs_info[partition .. " size_mb"] or "N/A"
84 fs_now.size_gb = fs_info[partition .. " size_gb"] or "N/A"
85 fs_now.used = fs_info[partition .. " used_p"] or "N/A"
86 fs_now.used_mb = fs_info[partition .. " used_mb"] or "N/A"
87 fs_now.used_gb = fs_info[partition .. " used_gb"] or "N/A"
88 fs_now.available = fs_info[partition .. " avail_p"] or "N/A"
89 fs_now.available_mb = fs_info[partition .. " avail_mb"] or "N/A"
90 fs_now.available_gb = fs_info[partition .. " avail_gb"] or "N/A"
92 notification_preset = fs.notification_preset
96 if notify == "on" and tonumber(fs_now.used) and tonumber(fs_now.used) >= 99 and not helpers.get_map(partition) then
98 preset = naughty.config.presets.critical,
100 text = partition .. " is full",
102 helpers.set_map(partition, true)
104 helpers.set_map(partition, false)
108 local notifycmd = (fs.options and string.format("dfs %s", fs.options)) or "dfs"
109 helpers.async(helpers.scripts_dir .. notifycmd, function(ws)
110 fs.notification_preset.text = ws:gsub("\n*$", "")
114 if showpopup == "on" then
115 fs.widget:connect_signal('mouse::enter', function () fs.show(0) end)
116 fs.widget:connect_signal('mouse::leave', function () fs.hide() end)
119 helpers.newtimer(partition, timeout, fs.update)