Index | Thread | Search

From:
obsd@mulh.net
Subject:
Re: cal: add option to highlight the current day
To:
tech@openbsd.org
Date:
Sun, 2 Aug 2026 01:53:18 -0400

Download raw body.

Thread
On 2026-08-01 20:01:19, Crystal Kolipe wrote:
> On Sat, Aug 01, 2026 at 07:47:25PM -0000, Crystal Kolipe wrote:
> > On Sat, Aug 01, 2026 at 04:08:06AM +0200, Piotr Durlej wrote:
> > > On Fri, Jul 31, 2026 at 05:29:15PM -0700, patrick keshishian wrote:
> > > > 
> > > > How about an environment variable to enable the highlight for
> > > > those who want this option, which can be put in their .profile,
> > > > retaining the age-long behavior as default for the rest?
> > > > 
> > > > Something like the following patch on top of your proposal.
> > > > 
> > > > --patrick
> > > 
> > > I'm not sure why this would be added to the base system cal(1), especially
> > > when ncal(1) already exists as a package and does the job.
> > 
> > If you just want highlighting of the current day, why not use the base cal
> > with sed:
> > 
> > $ cal | sed s/" `date +%e`"/"^[[92m&^[[39m"/
> > 
> > You can easily make that a shell alias.
> > 
> > The space before `date +%e` in the first quoted string ensures that single
> > digits only match the intended day.
> > 
> > Note that ^[ is escape, so if you're typing this at the console, then hit
> > control-v and then escape to enter the sequence.
> 
> Actually, it's better to match on either of the trailing space or newline:
> 
> $ cal | sed -E s/"`date +%e`( |$)"/"^[[92m&^[[39m"/

Use "tput" to get the standout codes, it's better then hardcoding ansi codes.
https://marc.info/?l=openbsd-tech&m=178327806197284&w=2

You also need to skip the first line otherwise you will fail on the 26th.

cal | sed "1!s/`date +%e`\>/`tput so`&`tput se`/"