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 markup = require("lain.util.markup")
12 local helpers = require("lain.helpers")
14 local beautiful = require("beautiful")
15 local wibox = require("wibox")
16 local naughty = require("naughty")
19 local string = { match = string.match }
20 local tonumber = tonumber
22 local setmetatable = setmetatable
24 -- File system disk space usage
27 local notification = nil
30 if notification ~= nil then
31 naughty.destroy(notification)
36 function fs:show(t_out)
39 local f = io.popen(helpers.scripts_dir .. "dfs")
40 ws = f:read("*all"):gsub("\n*$", "")
43 notification = naughty.notify({
50 -- Variable definitions
51 local unit = { ["mb"] = 1024, ["gb"] = 1024^2 }
53 local function worker(args)
54 local args = args or {}
55 local partition = args.partition or "/"
56 local refresh_timeout = args.refresh_timeout or 600
57 local header = args.header or " Hdd "
58 local header_color = args.header_color or beautiful.fg_normal or "#FFFFFF"
59 fs.color = args.color or beautiful.fg_focus or "#FFFFFF"
60 local footer = args.footer or " "
61 local shadow = args.shadow or false
63 local myfs = wibox.widget.textbox()
65 helpers.set_map("fs", false)
67 local fsupdate = function()
68 local fs_info = {} -- Get data from df
69 local f = io.popen("LC_ALL=C df -kP")
71 local function set_text()
72 local info = fs_info['{' .. partition .. ' used_p}']
73 myfs:set_markup(markup(header_color, header)
74 .. markup(fs.color, info .. footer))
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 helpers.uformat(fs_info, m .. " used", u, unit)
84 fs_info["{" .. m .. " used_p}"] = tonumber(p)
97 local part = fs_info['{' .. partition .. ' used_p}']
100 if part >= 99 and not helpers.get_map("fs") then
101 naughty.notify({ title = "warning",
102 text = partition .. " ran out!\n"
105 position = "top_right",
106 fg = beautiful.fg_urgent,
107 bg = beautiful.bg_urgent })
108 helpers.set_map("fs", true)
110 if shadow then set_text() end
114 local fstimer = timer({ timeout = refresh_timeout })
115 fstimer:connect_signal("timeout", fsupdate)
117 fstimer:emit_signal("timeout")
119 myfs:connect_signal('mouse::enter', function () fs:show(0) end)
120 myfs:connect_signal('mouse::leave', function () fs:hide() end)
125 show = function(t_out)
131 return setmetatable(fs_out, { __index = fs_out.widget })
134 return setmetatable(fs, { __call = function(_, ...) return worker(...) end })