Calendar with FvwmButtons

I’ve just made a little script you might interested in, so i share it. The script itself is quite quick & dirty, but the output looks good :)
Basically it is a yet-another-calendar, based on cal(1) and FvwmButtons, here is how it looks like:

The script is an ugly bash-script, full of escaping horror, and is a bit slow; a perl script would be surely better for this. So here is the script.

Run the script with three optional parameters: [day [month [year]]]. The output will be an FvwmButtons configuration, the configuration name is Cal, you can use it from a config file or from fvwmconsole like this:

PipeRead '~/cal' # today PipeRead '~/cal 31 12 2006' # new years eve, 2006

It uses and sets the 20,21,22,23 colorsets; if your config already uses these colorsets, you need to change these in the script everywhere where ‘Colorset’ appears.
You can also change the layout if you want sunday to be the first day of the week. For this, set the CAL variable in line 10 to ‘cal’.
You might also want to make it look like more similar to ‘cal’ by changing line 80 to: echo ${PREFIX}' (1x1, '`echo "$line" | sed 's/^\(..\)/Title "\1"/'`')'
(the change is the double-quoted “\1”, which makes the output like *Cal: (1x1 Title " 1"), and therefore the one-digit day numbers are not centered)

So that’s it, any comments are welcome.


Just one little thing, probably, where you put:

daylist=`${CAL} ${MONTH} ${YEAR} | tail +3 | grep -vx ^$ | sed 's/\(..\) /\1\n/g'`

You’d probably do better using

daylist=`${CAL} ${MONTH} ${YEAR} | tail -n +3 | grep -vx ^$ | sed 's/\(..\) /\1\n/g'`

Look at the “tail” part. +3 is discouraged, and not without a reason, because “+3” is a valid filename. It failed to open the file “+3” for read and died miserably. Using -n +3 all should be ok.

They’ve been deprecating that syntax for years, and whilst it will spit a warning out, it will still work… but we can improve upon the idea slightly:

[n6tadam@workstation ~]% cal 3 2007 | egrep -v '[A-Za-z]' | wc -w 

– Thomas Adam

Thanks for the improvement, Thomas. About the tail thing, I wouldn’t even have remembered about that if it weren’t cause in my case it wasn’t working (it spits out that file not found kind of error). So, not, it might work “usually”, but it doesn’t (not have to, as described in the man page) work.

I’ve just finished the python version of the calendar, and now it has some improvements, such as navigating between months, and holiday highlighting (new year, easter, pentecost and christmas).
main script here

There is a bash-script which the python script refers to, and which is responsible for navigating between months.
helper script here

For the navigating, i had to patch FvwmButtons to accept colorset changing via sendtomodule.
fvwmbuttons patch here

This is how I use it from my config:

 DestroyFunc OpenCalendar
 AddToFunc   OpenCalendar
  + I Next (Cal) nop
  + I TestRc (NoMatch) PipeRead ' && echo Module FvwmButtons -g +539+16 Cal'

 DestroyFunc CloseCalendar
 AddToFunc   CloseCalendar
  + I All (Cal) Close

Be sure to place the scripts to a location where fvwm can find them, or modify PATH, to do so.
The script uses (and defines) the colorsets 20 - 28, though it should be easy to change this behaviour.

Navigating between months is possible via mouse actions on the first row of the calendar:

wheel up (mouse 4) - next month wheel down (mouse 5) - previous month left click (mouse 1) - previous year right click (mouse 3) - next year middle click (mouse 2) - this year and month

– imp


 DestroyFunc OpenCalendar
 AddToFunc   OpenCalendar
  + I Next (Cal) nop
  + I TestRc (NoMatch) PipeRead ' && echo Module FvwmButtons -g +539+16 Cal'

So, that’d be:

None (Cal) ...

– Thomas Adam

sure, thanks
here is an image though: