Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Mal

macrumors 603
Original poster
Jan 6, 2002
6,253
30
Orlando
I'm looking for help with a little project of mine. I'm looking to modify the cal command that I've seen used for calendars in GeekTool to create a horizontal calendar. I don't care about days of the week so much, I just think it would be interesting to have all of the days of the week listed out in order at the bottom of my screen, with the current one marked.

So, I need two things:

I need to strip out of the cal command the days of the week at the top (or repeat them the appropriate number of times, but I imagine that will be far more difficult) and the line breaks at the end of each week. This is the most important part.

Secondly, I'd like to find a way to add bars (like this: |) on either side of the current date without replacing the numbers as most of the calendars I've seen have done it.

Here's the code I've seen:
Code:
cal | sed "s/^/ /;s/$/ /;s/ $(date +%e) / $(date +%e | sed 's/././g') /"

If I can just modify that to get what I want, that's fine, if I have to use something completely different, that's fine. I just would love to have a horizontal calendar.

jW
 
I realize this is almost a year later, but you can find what you're looking for here: http://www.macosxhints.com/article.php?story=20040625094428394

There's a post in particular you could look at:

Authored by: wallybear on Wed, Jul 7 2004 at 2:06PM PDT

but since I also like highlighting, I'll drop this to you as well:

cal_head=`cal | head -1`; cal_tail=`cal | tail -7`; today=`date "+%e"`; echo "$cal_head"; echo -en "${cal_tail/${today}/\033[1;32m${today}\033[0m}";


Edit: here's the code:

#!/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

if you can figure out how to incorporate that into a horizontal calendar, more power to you. (I haven't tried yet :) )
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.