mirror of https://github.com/lcpz/lain.git
Merge branch 'master' of https://github.com/copycat-killer/lain
This commit is contained in:
commit
137e072153
20
helpers.lua
20
helpers.lua
|
@ -13,6 +13,7 @@ local io = { open = io.open,
|
||||||
lines = io.lines,
|
lines = io.lines,
|
||||||
popen = io.popen }
|
popen = io.popen }
|
||||||
local rawget = rawget
|
local rawget = rawget
|
||||||
|
local table = { sort = table.sort }
|
||||||
|
|
||||||
-- Lain helper functions for internal use
|
-- Lain helper functions for internal use
|
||||||
-- lain.helpers
|
-- 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
|
return helpers
|
||||||
|
|
|
@ -9,9 +9,11 @@
|
||||||
|
|
||||||
local newtimer = require("lain.helpers").newtimer
|
local newtimer = require("lain.helpers").newtimer
|
||||||
local read_pipe = require("lain.helpers").read_pipe
|
local read_pipe = require("lain.helpers").read_pipe
|
||||||
|
local spairs = require("lain.helpers").spairs
|
||||||
|
|
||||||
local wibox = require("wibox")
|
local wibox = require("wibox")
|
||||||
|
|
||||||
|
local awful = require("awful")
|
||||||
local util = require("lain.util")
|
local util = require("lain.util")
|
||||||
|
|
||||||
local io = { popen = io.popen }
|
local io = { popen = io.popen }
|
||||||
|
@ -19,7 +21,6 @@ local os = { getenv = os.getenv }
|
||||||
local pairs = pairs
|
local pairs = pairs
|
||||||
local string = { len = string.len,
|
local string = { len = string.len,
|
||||||
match = string.match }
|
match = string.match }
|
||||||
local table = { sort = table.sort }
|
|
||||||
|
|
||||||
local setmetatable = setmetatable
|
local setmetatable = setmetatable
|
||||||
|
|
||||||
|
@ -33,13 +34,19 @@ local function worker(args)
|
||||||
local mailpath = args.mailpath or os.getenv("HOME") .. "/Mail"
|
local mailpath = args.mailpath or os.getenv("HOME") .. "/Mail"
|
||||||
local ignore_boxes = args.ignore_boxes or {}
|
local ignore_boxes = args.ignore_boxes or {}
|
||||||
local settings = args.settings or function() end
|
local settings = args.settings or function() end
|
||||||
|
local ext_mail_cmd = args.external_mail_cmd
|
||||||
|
|
||||||
maildir.widget = wibox.widget.textbox('')
|
maildir.widget = wibox.widget.textbox('')
|
||||||
|
|
||||||
function update()
|
function update()
|
||||||
|
if ext_mail_cmd ~= nil
|
||||||
|
then
|
||||||
|
awful.util.spawn(ext_mail_cmd)
|
||||||
|
end
|
||||||
|
|
||||||
-- Find pathes to mailboxes.
|
-- Find pathes to mailboxes.
|
||||||
local p = io.popen("find " .. mailpath ..
|
local p = io.popen("find " .. mailpath ..
|
||||||
" -mindepth 1 -maxdepth 1 -type d" ..
|
" -mindepth 1 -maxdepth 2 -type d" ..
|
||||||
" -not -name .git")
|
" -not -name .git")
|
||||||
local boxes = {}
|
local boxes = {}
|
||||||
repeat
|
repeat
|
||||||
|
@ -56,7 +63,7 @@ local function worker(args)
|
||||||
"-not -name '.*' -printf a")
|
"-not -name '.*' -printf a")
|
||||||
|
|
||||||
-- Strip off leading mailpath.
|
-- Strip off leading mailpath.
|
||||||
local box = string.match(line, mailpath .. "/*([^/]+)")
|
local box = string.match(line, mailpath .. "/(.*)")
|
||||||
local nummails = string.len(mailstring)
|
local nummails = string.len(mailstring)
|
||||||
if nummails > 0
|
if nummails > 0
|
||||||
then
|
then
|
||||||
|
@ -65,14 +72,13 @@ local function worker(args)
|
||||||
end
|
end
|
||||||
until line == nil
|
until line == nil
|
||||||
|
|
||||||
p:close()
|
p:close()
|
||||||
table.sort(boxes)
|
|
||||||
|
|
||||||
newmail = "no mail"
|
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
|
total = 0
|
||||||
|
|
||||||
for box, number in pairs(boxes)
|
for box, number in spairs(boxes)
|
||||||
do
|
do
|
||||||
-- Add this box only if it's not to be ignored.
|
-- Add this box only if it's not to be ignored.
|
||||||
if not util.element_in_table(box, ignore_boxes)
|
if not util.element_in_table(box, ignore_boxes)
|
||||||
|
|
|
@ -59,6 +59,7 @@ local function worker(args)
|
||||||
mpd_now = {
|
mpd_now = {
|
||||||
state = "N/A",
|
state = "N/A",
|
||||||
file = "N/A",
|
file = "N/A",
|
||||||
|
name = "N/A",
|
||||||
artist = "N/A",
|
artist = "N/A",
|
||||||
title = "N/A",
|
title = "N/A",
|
||||||
album = "N/A",
|
album = "N/A",
|
||||||
|
@ -71,6 +72,7 @@ local function worker(args)
|
||||||
for k, v in string.gmatch(line, "([%w]+):[%s](.*)$") do
|
for k, v in string.gmatch(line, "([%w]+):[%s](.*)$") do
|
||||||
if k == "state" then mpd_now.state = v
|
if k == "state" then mpd_now.state = v
|
||||||
elseif k == "file" then mpd_now.file = 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 == "Artist" then mpd_now.artist = escape_f(v)
|
||||||
elseif k == "Title" then mpd_now.title = escape_f(v)
|
elseif k == "Title" then mpd_now.title = escape_f(v)
|
||||||
elseif k == "Album" then mpd_now.album = escape_f(v)
|
elseif k == "Album" then mpd_now.album = escape_f(v)
|
||||||
|
|
|
@ -21,30 +21,27 @@ local setmetatable = setmetatable
|
||||||
|
|
||||||
-- Network infos
|
-- Network infos
|
||||||
-- lain.widgets.net
|
-- 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 function worker(args)
|
||||||
local args = args or {}
|
local net = { last_t = 0, last_r = 0 }
|
||||||
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()
|
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
|
||||||
|
local notify = args.notify or "on"
|
||||||
|
local screen = args.screen or 1
|
||||||
|
local settings = args.settings or function() end
|
||||||
|
local iface = args.iface or net.get_device()
|
||||||
|
|
||||||
net.widget = wibox.widget.textbox('')
|
net.widget = wibox.widget.textbox('')
|
||||||
|
|
||||||
|
@ -100,7 +97,8 @@ local function worker(args)
|
||||||
end
|
end
|
||||||
|
|
||||||
helpers.newtimer(iface, timeout, update)
|
helpers.newtimer(iface, timeout, update)
|
||||||
return net.widget
|
|
||||||
|
return setmetatable(net, { __index = net.widget })
|
||||||
end
|
end
|
||||||
|
|
||||||
return setmetatable(net, { __call = function(_, ...) return worker(...) end })
|
return setmetatable({}, { __call = function(_, ...) return worker(...) end })
|
||||||
|
|
2
wiki
2
wiki
|
@ -1 +1 @@
|
||||||
Subproject commit 35cc75dcb382fccdec6941698a1e96cc875fae1f
|
Subproject commit cefdc887c46f0f7c5d837d1449927e7dbf66b19e
|
Loading…
Reference in New Issue