From: Samir Benmendil Date: Mon, 6 Jan 2014 11:27:08 +0000 (+0100) Subject: conky: add mail check + change font X-Git-Url: https://git.rmz.io/dotfiles.git/commitdiff_plain/97546c0717e183d360a0375064130e20a7682990 conky: add mail check + change font --- diff --git a/conky/awesome.png b/conky/awesome.png new file mode 100644 index 0000000..5b08e53 Binary files /dev/null and b/conky/awesome.png differ diff --git a/conky/logo.png b/conky/chakra.png similarity index 100% rename from conky/logo.png rename to conky/chakra.png diff --git a/conky/functions.lua b/conky/functions.lua new file mode 100644 index 0000000..918914f --- /dev/null +++ b/conky/functions.lua @@ -0,0 +1,82 @@ +--[[ + + Licensed under GNU General Public License v2 + * (c) 2014, Samir Benmendil + * (c) 2013, Luke Bonham + * (c) 2010-2012, Peter Hofmann + +--]] + +local io = io +local os = { getenv = os.getenv } +local pairs = pairs +local string = { len = string.len, + match = string.match, + format = string.format, + sub = string.sub } + +-- Maildir check +-- lain.widgets.maildir +local maildir = {} +local newmail + +function conky_mail() + local updates=tonumber(conky_parse('${updates}')) + if newmail and updates % 30 ~= 0 then + return newmail + end + local mailpath = os.getenv("HOME") .. "/mail" + + -- Find pathes to mailboxes. + local dirs = io.popen("find " .. mailpath .. " -type d -name new -or -name cur -prune") + local boxes = {} + for line in dirs:lines() do + -- Strip off leading mailpath. + local acc = string.match(line, mailpath.."/*([^/]+)") + local box = string.match(line, mailpath..'/'..acc.."/*([^/]+)") + if boxes[acc] == nil then + boxes[acc] = {} + end + if boxes[acc][box] == nil then + boxes[acc][box] = {} + end + + -- Find all files in the "new" subdirectory. For each + -- file, print a single character (no newline). Don't + -- match files that begin with a dot. + -- Afterwards the length of this string is the number of + -- new mails in that box. + if line:sub(-3) == 'new' then + local new = io.popen("find " .. line .. " -type f -not -name '.*' -printf a") + cnt_new = string.len(new:read("*all")) + if cnt_new > 0 then + boxes[acc][box]['cnt_new'] = string.format("${color e6db74}%5d${color}", cnt_new) + else + boxes[acc][box]['cnt_new'] = string.format("%5d", cnt_new) + end + elseif line:sub(-3) == 'cur' then + local old = io.popen("find " .. line .. " -type f -not -name '*:2,*S*' -printf a") + cnt_old = string.len(old:read("*all")) + if cnt_old > 0 then + boxes[acc][box]['cnt_old'] = string.format("${color fd971f}%2d${color}", cnt_old) + else + boxes[acc][box]['cnt_old'] = string.format("%2d", cnt_old) + end + end + end + + newmail = "" + local accounts = {"gmail"} + local mailboxes = { {"inbox", "chakra"}, + {"youtube", "unimaas"}} + for a, acc in pairs(accounts) do + for b, box in ipairs(mailboxes) do + local boxl = boxes[acc][box[1]] + local boxr = boxes[acc][box[2]] + newmail = newmail .. string.format("%10s:%s/%s", box[1], boxl['cnt_new'], boxl['cnt_old']) + newmail = newmail .. string.format("%11s:%s/%s\n", box[2], boxr['cnt_new'], boxr['cnt_old']) + end + end + newmail = string.sub(newmail, 1 , #newmail - 1) + return newmail +end diff --git a/conkyrc b/conkyrc index 8120781..a5c79df 100644 --- a/conkyrc +++ b/conkyrc @@ -13,7 +13,7 @@ format_human_readable use_xft yes override_utf8_locale yes -xftfont Droid Sans:style=Bold:size=10 +xftfont Anonymous Pro:style=Bold:size=11 text_buffer_size 2048 own_window yes @@ -47,10 +47,12 @@ update_interval 2 uppercase no use_spacer none +lua_load ~/.conky/functions.lua + TEXT -${image ~/.conky/logo.png -p 0,15 -s 19x19} +${image ~/.conky/chakra.png -p 10,15 -s 70x70} +${image ~/.conky/awesome.png -p 100,15 -s 70x70}# ${font Droid Sans:style=Bold:size=24}${alignr}${time %R} -${font Droid Sans:style=Bold:size=12}${color 75D1FF}DATE${color 1B71CC}$hr${color}${font} ${font Droid Sans:style=Bold:size=12}${alignr}${time %a, %e %b %Y}${font} ${font Droid Sans:style=Bold:size=12}${color 75D1FF}SYSTEM${color 1B71CC}$hr${color}${font} Kernel: ${alignr}${kernel} @@ -58,9 +60,16 @@ Uptime: ${alignr}${uptime} # |--Updates Updates: ${alignr}${font Droid Sans:style=Bold:size=10}${execpi 600 checkupdates | wc -l | sed '/^0$/! s/^\(.*\)$/${color 75D1FF}\1${color}/' }${font} Package(s) +# |--Mail +${font Droid Sans:style=Bold:size=12}${color 75D1FF}MAIL${color 1B71CC}$hr${color}${font} +${lua_parse mail} + +# |--MPD +${font Droid Sans:style=Bold:size=12}${color 75D1FF}MPD${color 1B71CC}$hr${color}${font} + # |--CPU ${font Droid Sans:style=Bold:size=12}${color 75D1FF}CPU${color 1B71CC}$hr${color}${font} -${exec grep "model name" /proc/cpuinfo | uniq | cut -d':' -f2} +${color AAAAAA}${exec grep "model name" /proc/cpuinfo | uniq | sed 's/.*: //'}${color} ${if_empty ${cpu cpu1}}${else}Core 0 @ ${color 75D1FF}${alignr 65}${cpu cpu1}%${alignr}${cpubar cpu1 7,150}${color} ${endif}${if_empty ${cpu cpu2}}${else}Core 1 @ ${color 75D1FF}${alignr 65}${cpu cpu2}%${alignr}${cpubar cpu2 7,150}${color} ${endif}${if_empty ${cpu cpu3}}${else}Core 2 @ ${color 75D1FF}${alignr 65}${cpu cpu3}%${alignr}${cpubar cpu3 7,150}${color} @@ -81,7 +90,7 @@ ${swap}/${swapmax}${alignr}${color 75D1FF}${swapbar 8,150}${color} # |--PROC ${font Droid Sans:style=Bold:size=12}${color 75D1FF}TOP${color 1B71CC}$hr${color}${font} -${color AAAAAA}PROCESS${alignr 90}CPU${alignr}RAM${color} +${color AAAAAA}PROCESS${alignr 120}CPU${alignr 20}RAM${color} ${top name 1}${alignr 80}${top cpu 1}${alignr}${top mem 1} ${top name 2}${alignr 80}${top cpu 2}${alignr}${top mem 2} ${top name 3}${alignr 80}${top cpu 3}${alignr}${top mem 3}