From d659c34974ee8e2c136bbac2424c5d95b889492d Mon Sep 17 00:00:00 2001 From: copycat-killer Date: Wed, 11 Nov 2015 18:25:51 +0100 Subject: [PATCH 1/9] #150 fix; wiki updated --- widgets/net.lua | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/widgets/net.lua b/widgets/net.lua index a578ae4..702937c 100644 --- a/widgets/net.lua +++ b/widgets/net.lua @@ -21,22 +21,20 @@ local setmetatable = setmetatable -- Network infos -- lain.widgets.net -local net = { - last_t = 0, - last_r = 0 -} - -function net.get_device() - local ws = helpers.read_pipe("ip link show | cut -d' ' -f2,9") - ws = ws:match("%w+: UP") or ws:match("ppp%w+: UNKNOWN") - if ws ~= nil then - return ws:match("(%w+):") - else - return "network off" - end -end local function worker(args) + local net = { last_t = 0, last_r = 0 } + + function net.get_device() + local ws = helpers.read_pipe("ip link show | cut -d' ' -f2,9") + ws = ws:match("%w+: UP") or ws:match("ppp%w+: UNKNOWN") + if ws ~= nil then + return ws:match("(%w+):") + else + return "network off" + end + end + local args = args or {} local timeout = args.timeout or 2 local units = args.units or 1024 --kb @@ -100,7 +98,8 @@ local function worker(args) end helpers.newtimer(iface, timeout, update) - return net.widget + + return setmetatable(net, { __index = net.widget }) end -return setmetatable(net, { __call = function(_, ...) return worker(...) end }) +return setmetatable({}, { __call = function(_, ...) return worker(...) end }) From d58ac139b6198118314a4fe640abe18e3f816380 Mon Sep 17 00:00:00 2001 From: copycat-killer Date: Wed, 11 Nov 2015 18:30:59 +0100 Subject: [PATCH 2/9] wiki updated --- wiki | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wiki b/wiki index 35cc75d..cb5d545 160000 --- a/wiki +++ b/wiki @@ -1 +1 @@ -Subproject commit 35cc75dcb382fccdec6941698a1e96cc875fae1f +Subproject commit cb5d5455987533d08c37fd17fec7dfa757b7130a From da1410677b338d57f4e4082587197b3a38985207 Mon Sep 17 00:00:00 2001 From: copycat-killer Date: Wed, 11 Nov 2015 18:52:40 +0100 Subject: [PATCH 3/9] #150 fix 2 --- widgets/net.lua | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/widgets/net.lua b/widgets/net.lua index 702937c..af823a8 100644 --- a/widgets/net.lua +++ b/widgets/net.lua @@ -35,14 +35,13 @@ local function worker(args) end end - local args = args or {} - local timeout = args.timeout or 2 - local units = args.units or 1024 --kb - local notify = args.notify or "on" - local screen = args.screen or 1 + local args = args or {} + local timeout = args.timeout or 2 + local units = args.units or 1024 --kb + local notify = args.notify or "on" + local screen = args.screen or 1 local settings = args.settings or function() end - - iface = args.iface or net.get_device() + local iface = args.iface or net.get_device() net.widget = wibox.widget.textbox('') From 11e448e5e2260fbbcb63f1303bbc00d0d8ddcbbd Mon Sep 17 00:00:00 2001 From: copycat-killer Date: Thu, 12 Nov 2015 11:51:53 +0100 Subject: [PATCH 4/9] (re)merged #142 --- widgets/mpd.lua | 2 ++ 1 file changed, 2 insertions(+) diff --git a/widgets/mpd.lua b/widgets/mpd.lua index 5af898b..1972050 100644 --- a/widgets/mpd.lua +++ b/widgets/mpd.lua @@ -59,6 +59,7 @@ local function worker(args) mpd_now = { state = "N/A", file = "N/A", + name = "N/A", artist = "N/A", title = "N/A", album = "N/A", @@ -71,6 +72,7 @@ local function worker(args) for k, v in string.gmatch(line, "([%w]+):[%s](.*)$") do if k == "state" then mpd_now.state = v elseif k == "file" then mpd_now.file = v + elseif k == "Name" then mpd_now.name = escape_f(v) elseif k == "Artist" then mpd_now.artist = escape_f(v) elseif k == "Title" then mpd_now.title = escape_f(v) elseif k == "Album" then mpd_now.album = escape_f(v) From 418e475b5b4eb8404e115d74fdb3756169877278 Mon Sep 17 00:00:00 2001 From: Sudo Nice Date: Wed, 18 Nov 2015 11:02:16 +0300 Subject: [PATCH 5/9] helpers: spairs() added --- helpers.lua | 20 ++++++++++++++++++++ widgets/maildir.lua | 7 +++---- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/helpers.lua b/helpers.lua index 4e90e16..4ece329 100644 --- a/helpers.lua +++ b/helpers.lua @@ -13,6 +13,7 @@ local io = { open = io.open, lines = io.lines, popen = io.popen } local rawget = rawget +local table = { sort = table.sort } -- Lain helper functions for internal use -- lain.helpers @@ -113,4 +114,23 @@ end -- }}} +--{{{ Iterate over table of records sorted by keys +function helpers.spairs(t) + -- collect the keys + local keys = {} + for k in pairs(t) do keys[#keys+1] = k end + + table.sort(keys) + + -- return the iterator function + local i = 0 + return function() + i = i + 1 + if keys[i] then + return keys[i], t[keys[i]] + end + end +end +--}}} + return helpers diff --git a/widgets/maildir.lua b/widgets/maildir.lua index eed6138..79d28b5 100644 --- a/widgets/maildir.lua +++ b/widgets/maildir.lua @@ -9,6 +9,7 @@ local newtimer = require("lain.helpers").newtimer local read_pipe = require("lain.helpers").read_pipe +local spairs = require("lain.helpers").spairs local wibox = require("wibox") @@ -19,7 +20,6 @@ local os = { getenv = os.getenv } local pairs = pairs local string = { len = string.len, match = string.match } -local table = { sort = table.sort } local setmetatable = setmetatable @@ -65,14 +65,13 @@ local function worker(args) end until line == nil - p:close() - table.sort(boxes) + p:close() newmail = "no mail" -- Count the total number of mails irrespective of where it was found total = 0 - for box, number in pairs(boxes) + for box, number in spairs(boxes) do -- Add this box only if it's not to be ignored. if not util.element_in_table(box, ignore_boxes) From 1539a1b5d4394c6a397e3a68f36f9ba66d161a4b Mon Sep 17 00:00:00 2001 From: Lee Watson Date: Sat, 21 Nov 2015 11:49:22 +0000 Subject: [PATCH 6/9] Add ability to run an external mail update command, and support multi-level maildirs containing multiple accounts. --- widgets/maildir.lua | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/widgets/maildir.lua b/widgets/maildir.lua index 79d28b5..4f3fc79 100644 --- a/widgets/maildir.lua +++ b/widgets/maildir.lua @@ -33,14 +33,19 @@ local function worker(args) local mailpath = args.mailpath or os.getenv("HOME") .. "/Mail" local ignore_boxes = args.ignore_boxes or {} local settings = args.settings or function() end + local ext_mail_cmd = args.external_mail_cmd maildir.widget = wibox.widget.textbox('') function update() + if ext_mail_cmd ~= nil + then + awful.util.spawn(ext_mail_cmd) + end -- Find pathes to mailboxes. local p = io.popen("find " .. mailpath .. - " -mindepth 1 -maxdepth 1 -type d" .. - " -not -name .git") + " -mindepth 1 -maxdepth 2 -type d" .. + " -not -name .git") local boxes = {} repeat line = p:read("*l") @@ -56,7 +61,7 @@ local function worker(args) "-not -name '.*' -printf a") -- Strip off leading mailpath. - local box = string.match(line, mailpath .. "/*([^/]+)") + local box = string.match(line, mailpath .. "/(.*)") local nummails = string.len(mailstring) if nummails > 0 then From 94204ac2dad82e8b9b206cb596b3a27fb8379640 Mon Sep 17 00:00:00 2001 From: Lee Watson Date: Sat, 21 Nov 2015 11:53:19 +0000 Subject: [PATCH 7/9] Styling to match upstream --- widgets/maildir.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/widgets/maildir.lua b/widgets/maildir.lua index 4f3fc79..12f3545 100644 --- a/widgets/maildir.lua +++ b/widgets/maildir.lua @@ -44,8 +44,8 @@ local function worker(args) end -- Find pathes to mailboxes. local p = io.popen("find " .. mailpath .. - " -mindepth 1 -maxdepth 2 -type d" .. - " -not -name .git") + " -mindepth 1 -maxdepth 2 -type d" .. + " -not -name .git") local boxes = {} repeat line = p:read("*l") From 35957f391460172500255ffe20cf1b34622d93f1 Mon Sep 17 00:00:00 2001 From: Lee Watson Date: Sat, 21 Nov 2015 11:56:32 +0000 Subject: [PATCH 8/9] Fix missing awful --- widgets/maildir.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/widgets/maildir.lua b/widgets/maildir.lua index 12f3545..2476601 100644 --- a/widgets/maildir.lua +++ b/widgets/maildir.lua @@ -13,6 +13,7 @@ local spairs = require("lain.helpers").spairs local wibox = require("wibox") +local awful = require("awful") local util = require("lain.util") local io = { popen = io.popen } From 7dd6443f0a87e0816f5b6323a23bf3e8ca364aee Mon Sep 17 00:00:00 2001 From: copycat-killer Date: Sun, 22 Nov 2015 09:16:35 +0100 Subject: [PATCH 9/9] maildir: spaceline added --- widgets/maildir.lua | 1 + wiki | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/widgets/maildir.lua b/widgets/maildir.lua index 2476601..c9937b4 100644 --- a/widgets/maildir.lua +++ b/widgets/maildir.lua @@ -43,6 +43,7 @@ local function worker(args) then awful.util.spawn(ext_mail_cmd) end + -- Find pathes to mailboxes. local p = io.popen("find " .. mailpath .. " -mindepth 1 -maxdepth 2 -type d" .. diff --git a/wiki b/wiki index cb5d545..cefdc88 160000 --- a/wiki +++ b/wiki @@ -1 +1 @@ -Subproject commit cb5d5455987533d08c37fd17fec7dfa757b7130a +Subproject commit cefdc887c46f0f7c5d837d1449927e7dbf66b19e