Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Even more fun with cal and GeekTool' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Even more fun with cal and GeekTool
Authored by: redclawx on Jun 30, '04 09:48:32PM
I have been able to combine several of the above comments together to get a three calendar layout. The layout is month below month, not month next to month but it's better than nothing. Also the alignment between the months isn't exact. The current month is indented by 1 character, while the previous and next month aren't. The original code was written by wallybear and dILVISH. Also the rewritten code works just fine with GeekTool, even on multiple lines (I've set up a Shell entry on my system.)

#!/bin/sh

month=`date +%m`
year=`date +%Y`

nextMonth=$(($month+1))
lastMonth=$(($month-1))

if [[ $nextMonth -gt 12 ]]
then
        nextMonth=1
        year=$(($year+1))
fi

if [[ $lastMonth -eq 0 ]]
then
        lastMonth=12
        year=$(($year-1))
fi

cal $lastMonth $year
cal | awk '{ if (substr($0,1,2) == " 1")  print "                    1 "; \
do { prevline=$0; if (getline == 0) exit; print " "\
substr(prevline,0) " "; } while (1) }' | \
awk -v cday=`date "+%d"` '{ a=$0; sub(" "fill int(cday)" ","["fill int(cday)"]",a); print  a };'
echo
cal $nextMonth $year


[ Reply to This | # ]
Even more fun with cal and GeekTool
Authored by: siliconjones on Jul 07, '04 10:23:17AM

I know its dreadfully simple butů

date | cal

appears to work.

[ Reply to This | # ]
Even more fun with cal and GeekTool
Authored by: wallybear on Jul 07, '04 11:09:52AM
where's the difference?

cal and date | cal give the same identical output...

so why date | cal ?


[ Reply to This | # ]
Here is on three columns, but...
Authored by: wallybear on Jul 07, '04 02:06:36PM
Here is a simple modification to get the three months on three columns using the handy pr command:

#!/bin/sh

month=`date +%m`
year=`date +%Y`

nextMonth=$(($month+1))
lastMonth=$(($month-1))

if [[ $nextMonth -gt 12 ]]
then
        nextMonth=1
        year=$(($year+1))
fi

if [[ $lastMonth -eq 0 ]]
then
        lastMonth=12
        year=$(($year-1))
fi

doCal()
{
cal $lastMonth $year
cal | awk '{ if (substr($0,1,2) == " 1")  print "                    1 "; \
do { prevline=$0; if (getline == 0) exit; print " "\
substr(prevline,0) " "; } while (1) }' | \
awk -v cday=`date "+%d"` '{ a=$0; sub(" "fill int(cday)" ","["fill int(cday)"]",a); print  a };'
echo
cal $nextMonth $year
}


doCal | pr -3 -t
This will get you the following result in Terminal:

     June 2004                July 2004             August 2004
 S  M Tu  W Th  F  S    S  M Tu  W Th  F  S    S  M Tu  W Th  F  S
       1  2  3  4  5                1  2  3    1  2  3  4  5  6  7
 6  7  8  9 10 11 12    4  5  6 [7] 8  9 10    8  9 10 11 12 13 14
13 14 15 16 17 18 19   11 12 13 14 15 16 17   15 16 17 18 19 20 21
20 21 22 23 24 25 26   18 19 20 21 22 23 24   22 23 24 25 26 27 28
27 28 29 30            25 26 27 28 29 30 31   29 30 31
but...
while on Terminal the display is correct, GeekTool shows erratic behaviour in some column (a GeekTool displaying bug, I presume; no tabs or other strange characters are contained here).
Any suggestion?

[ Reply to This | # ]