CLI Magic: Birthday

54

Author: Joe Barr

The older I get, the more I need little memory aids to keep track of things like birthdays, appointments, anniversaries, and events. I’ve recently added another item to my collection of useful CLI apps. It’s called birthday, and it helps me keep up with them. Like most CLI apps, it’s light and fast and easy to use. Set your snooze alarm for right now, and meet me on the CLI.Birthday is a data driven application, so this time around, we’ll start with the data and then proceed to the executable. You’ll need a file named .birthdays in your home directory to hold all the dates you deem important. The basic format for an entry in birthdays is this: Name of person or event, an = sign, the date to remember in DD/MM or DD/MM/YYYY format, and any options that might be specified. Yes, those are British date formats, with days preceding months. We’ll either have to live with it or patch the code to fit our tastes. Oh, bother.

One of the options allows you to indicate the type of date being recorded. If no option for the type is given, it is assumed to be a birthday. Here is the complete list of choices for type of date. So for Susan’s birthday, all I need to enter is:

Susan=21/06

Here are some of the options available to use with your date entries:

  • bd Birthday
  • ann Anniversary
  • ev Event
  • wn days Warn days in advance of date
  • todate Event lasts until this date
  • fordays days Event runs for days

My entry for the Novell Brainshare coming up this month looks like this:

Brainshare=20/03/2005 ev fordays 6

Enough data already, let’s get the executable. I installed Birthday from the Debian repository. Source and executable RPMs are also available for other distributions. If you want to hack the date format, of course, you’ll need the source. For today’s exercise, all you need is the executable.

Birthday won’t do much until you create the .birthdays text file using the format described above. Once you have that chore done, it’s ready to go. Here is what mine looks like for the near future:

Susan=21/06/19xx bd
Susan=04/02/1999 an
Brainshare=20/03/2005 ev fordays 6
Ides of March=15/03 ev
Paula=03/04 bd
Taxes=15/04 ev

The default warning period is 21 days, so simply entering birthday at the CLI produces:

Ides of March in 1 week's time.
Brainshare for 1 day in 1 week and 5 days' time.

The event horizon can be expanded with the addition of a command line argument, like this:

birday -W 90

Which produces:

Ides of March in 1 week's time.
Brainshare for 1 day in 1 week and 5 days' time.
Paula has a birthday in 3 weeks and 5 days' time.
Taxes in 1 month and 1 week's time.

You can also format the output as a calendar, suitable for printing. Like this:

birthday -c

The calendar format option looks like this.

---Saturday-April-02-2005-------------------------------------------------------





---Sunday-April-03-2005---------------------------------------------------------
Paula has a birthday



 

An entry like those above is printed for each day in the warning period. I am only showing two days in this example to conserve space.

Other command line options allow you set the warning period to weeks, adjust the width of the calendar output, use another file as input, and adjust the number of lines printed for each day. For the details on those, see the man page.