vicious/widgets/mdir_all.lua

43 lines
1.4 KiB
Lua
Raw Normal View History

2009-09-29 22:33:19 +02:00
---------------------------------------------------
-- Licensed under the GNU General Public License v2
2010-01-02 21:21:54 +01:00
-- * (c) 2010, Adrian C. <anrxc@sysphere.org>
2009-09-29 22:33:19 +02:00
-- * (c) Maildir Biff Widget, Fredrik Ax
---------------------------------------------------
-- {{{ Grab environment
local type = type
local helpers = require"vicious.helpers"
local spawn = require"vicious.spawn"
-- }}}
2010-03-02 23:19:44 +01:00
-- Mdir: provides the number of new and unread messages in Maildir structures/dirs
-- vicious.widgets.mdir
2017-01-25 17:53:14 +01:00
local mdir_all = {}
-- {{{ Maildir widget type
function mdir_all.async(format, warg, callback)
if type(warg) ~= "table" then return callback{} end
local starting_points = ""
for i,dir in ipairs(warg) do
starting_points = starting_points .. " " .. helpers.shellquote(dir)
end
if starting_points == "" then return callback{ 0, 0 } end
local new, cur = 0, 0
spawn.with_line_callback(
"find" .. starting_points .. " -type f -regex '.*/cur/.*2,[^S]*$';",
{ stdout = function (filename) cur = cur + 1 end,
output_done = function ()
spawn.with_line_callback(
"find" .. starting_points .. " -type f -path '*/new/*';",
{ stdout = function (filename) new = new + 1 end,
output_done = function () callback{ new, cur } end })
end })
end
-- }}}
return helpers.setasyncall(mdir_all)