X-Git-Url: https://git.madduck.net/etc/awesome.git/blobdiff_plain/b7c3cb77a1ca72ab8fb91c8618f8703e3c1e446c..7de62e4d9fe0d3a7521fc72a66c905d6f343c27b:/widgets/maildir.lua diff --git a/widgets/maildir.lua b/widgets/maildir.lua index bd79221..8cb821d 100644 --- a/widgets/maildir.lua +++ b/widgets/maildir.lua @@ -8,12 +8,13 @@ --]] local newtimer = require("lain.helpers").newtimer +local read_pipe = require("lain.helpers").read_pipe local wibox = require("wibox") local util = require("lain.util") -local io = io +local io = { popen = io.popen } local os = { getenv = os.getenv } local pairs = pairs local string = { len = string.len, @@ -24,7 +25,7 @@ local setmetatable = setmetatable -- Maildir check -- lain.widgets.maildir -local maildir = {} +local maildir = { total = 0 } local function worker(args) local args = args or {} @@ -50,10 +51,9 @@ local function worker(args) -- match files that begin with a dot. -- Afterwards the length of this string is the number of -- new mails in that box. - local np = io.popen("find " .. line .. + local mailstring = read_pipe("find " .. line .. "/new -mindepth 1 -type f " .. "-not -name '.*' -printf a") - local mailstring = np:read("*a") -- Strip off leading mailpath. local box = string.match(line, mailpath .. "/*([^/]+)") @@ -65,10 +65,11 @@ local function worker(args) end until line == nil + p:close() table.sort(boxes) newmail = "no mail" - --Count the total number of mails irrespective of where it was found + -- Count the total number of mails irrespective of where it was found total = 0 for box, number in pairs(boxes) @@ -87,8 +88,10 @@ local function worker(args) end end - widget = maildir.widget - settings() + if maildir.total ~= total then + widget = maildir.widget + settings() + end end newtimer(mailpath, timeout, update, true)