14,000 hints and counting!

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: mrchaotica on Jul 09, '04 01:09:56AM
there's one serious issue with your script: When the month is december or january, it wil display the wrong year, since you only calculate it once. If it's december, you have to call only the next month with "year + 1", and if it's january, you have to call only the previous month with "year - 1" Here's the fix:
``````
#!/bin/zsh

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

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

if [[ \$month -eq 1 ]]
then
lastMonth=12
cal \$lastMonth \$((\$year-1)) | awk '{ print \$0; while (getline != 0 ) { print " "\$0 }}'
else
cal \$lastMonth \$year | awk '{ print \$0; while (getline != 0 ) { print " "\$0 }}'
fi

cal | awk -v cday=`date "+%d"` '{ fill=(int(cday)>9?"":" "); print " "\$0; getline; print " "\$0; while (getline != 0) {a=" "\$0" "; sub(" "fill int(cday)" ",fill "(" int(cday)")", a); print a }}'

if [[ \$month -eq 12 ]]
then
nextMonth=1
cal \$nextMonth \$((\$year+1)) | awk '{ print \$0; while (getline != 0 ) { print " "\$0 }}'
else
cal \$nextMonth \$year | awk '{ print \$0; while (getline != 0 ) { print " "\$0 }}'
fi
``````