[Remind-Fans] Sliding calendar starting from today ? (continued)

Derek derekmthomas at telus.net
Sat Jun 25 01:09:53 EDT 2011


Just to give you an idea:

Here's input.rem:

  BANNER %
  saturday sunday thursday msg %y-%t-%r category: work Present report.%
  tuesday wednesday msg %y-%t-%r category: home Clean kitchen.%
  july 4 2011 through july 12 2011 msg %y-%t-%r category: market Fish stock.%
  sunday msg %y-%t-%r Relax.%
  thursday at 19:00 msg %y-%t-%r Continue reading "Anna Kerenina."%

Here's color_rem.awk:

  BEGIN{
    color["default"]="37"
    color["work"]="31"
    color["home"]="32"
    color["market"]="36"
  }
  {
    printf $1
    msg=substr($0, match($0, " "))
    categ_re="category: [^ ][^ ]*"
    match(msg, categ_re)
    printf("\033[" \
      color[substr(msg, RSTART+length("category: "), RLENGTH-length("category: "))] "m" \
      "%s\033[" color["default"] "m\n", 
      substr(msg, RLENGTH+2))
  }

Here's your pipeline:

$ remind -h - '*30' < input.rem | awk -f color_rem.awk


This awk program is very fragile and not very generalizable,
but maybe it's an okay place to start hacking.
To be colorized, an input rec must have the string "category: "
concatenated with one of the strings "work", "home", or "market".
It also needs a leading non-blank date expression such as the one repeated in input.rem.
It would be preferable to add another filter to save you having to re-type it in every msg:

$ sed 's/ [Mm][Ss][Gg] /&%y-%t-%r /' input.rem | remind -h - '*30' | awk -f color_rem.awk

...And then, for example, the final line of input.rem would be merely:

  thursday at 19:00 msg Continue reading "Anna Kerenina."%

Incidentally, awk really isn't that hard and I still think if you become comfortable with only one language, awk should be it.  There 
aren't any languages I know of that are both simpler and more powerful.  It's ubiquitous--I haven't even seen many embedded systems without it.  And it does practically everything the average user could possibly need--most of which with remarkable ease.

-Derek



More information about the Remind-fans mailing list