From 89980d9fa8ca89ecef068949fc510318b0e9e875 Mon Sep 17 00:00:00 2001 From: luke bonham Date: Wed, 17 Jul 2013 19:44:06 +0200 Subject: [PATCH] dremora: cool cal perfected --- rc.lua.dremora | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/rc.lua.dremora b/rc.lua.dremora index fc90e47..c00f355 100755 --- a/rc.lua.dremora +++ b/rc.lua.dremora @@ -164,6 +164,7 @@ gray = "" mytextclock = awful.widget.textclock(white .. "%H:%M" .. coldef) -- attached calendar +local tonumber = tonumber local calendar = nil local offset = 0 @@ -178,24 +179,26 @@ function show_calendar(inc_offset, t_out) remove_calendar() local c_text - if inc_offset == 0 or offset ~= 0 then + if inc_offset == 0 then local f = io.popen('/usr/bin/cal | sed -r -e "s/(^| )(`date +\\"%d\\"`)($| )/\\1\\2<\\/span><\\/b>\\3/"',"r") c_text = "" .. f:read() .. "\n\n" .. f:read() .. "\n" .. f:read("*all") .. "" f:close() offset = 0 else - local month = os.date('%m') - local year = os.date('%Y') + local month = tonumber(os.date('%m')) + local year = tonumber(os.date('%Y')) + offset = offset + inc_offset - if month == '12' and inc_offset == 1 then - month = 1 - year = year + 1 - elseif month == '1' and inc_offset == -1 then + month = month + offset + + if month > 12 then month = 12 - year = year - 1 - else month = month + offset + offset = 12 - tonumber(os.date('%m')) + elseif month < 1 then + month = 1 + offset = 1 - tonumber(os.date('%m')) end - + f = io.popen('/usr/bin/cal ' .. month .. ' ' .. year ,"r") c_text = "" .. f:read() .. "\n\n" .. f:read() .. "\n" .. f:read("*all") .. "" f:close()