conky calendar

Richard Mahlerwein mahlerrd at yahoo.com
Sat Oct 10 14:41:20 UTC 2009


>From: Roland Smith <rsmith at xs4all.nl>
>Subject: Re: conky calendar
>To: "PJ" <af.gourmet at videotron.ca>
>Cc: freebsd-questions at freebsd.org
>Date: Saturday, October 10, 2009, 9:27 AM
>
>On Sat, Oct 10, 2009 at 05:01:34AM -0400, PJ wrote:
>> I'm having a bit of a time with the calendar.sh script I 
>> found on the Net; it doesn't display quite correctly.
>> It should have brackets around the current date, but I 
>> can't figure out what is not functioning correctly:
>> 
>> #!/bin/sh
>> cal | awk 'NR>2' | sed -e 's/   /    /g' -e 's/[^ ] /& /g' -e 's/..*/  & /' -e 's/ \('`date | awk '{print $2}'`'\) /\['`date | awk '{print $2}'`'\]/'
>
>Look at the output of the date command:
>Sat Oct 10 15:12:39 CEST 2009
>
>Change 'print $2' to 'print $3' to get the numercal date.
>Or even simpler: use "date +%d" instead of "date | awk '{print $3}'".
>
>Roland

I could not get it to work until I changed the single quotes in the last -e expression to double quotes.  (This either interactively under csh or as a script under sh).  BTW, using `date +%s` and with an additional minor change to make the numbers continue to line up ... Oh!  This will not fix mis-alignments on days when it is not the end of the week, I don't think ... anyway.

cal | awk 'NR>1' | sed -e 's/   /    /g' -e 's/[^ ] /& /g' -e 's/..*/  &/' -e "s/\ `date +%d`/\[`date +%d`\]/"

Gives
$ sh newcal.sh
  Su  Mo  Tu  We  Th  Fr  Sa
                   1   2   3
   4   5   6   7   8   9 [10]
  11  12  13  14  15  16  17
  18  19  20  21  22  23  24
  25  26  27  28  29  30  31

Now, if you had a space character at the end of each line, you could do something like ...

cal | awk 'NR>1' | sed -e 's/   /    /g' -e 's/[^ ] /& /g' -e 's/..*/  &/' -e "s/\ `date +%d`\ /\[`date +%d`\]/"

And then it would replace (underscore is space) "_8_" with "[8]" so it would always line up.  You can't do that without the space at the end of the line because the trailing numbers look like this "_17" not "_17_".  But, fix that, and you can use the above.  That is left as an exercise for the reader.  

-Rich


      


More information about the freebsd-questions mailing list