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


Click here to return to the 'Here is on three columns, but...' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
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 | # ]