Index | Thread | Search

From:
obsd@mulh.net
Subject:
Re: cal: add option to highlight the current day
To:
tech@openbsd.org
Date:
Wed, 5 Aug 2026 16:05:24 -0400

Download raw body.

Thread
  • obsd@mulh.net:

    cal: add option to highlight the current day

On 2026-08-02 6:21:06, kolipe.c () exoticsilicon ! com wrote:
> On Sun, Aug 02, 2026 at 08:14:22AM +0200, landry () openbsd ! org wrote:
> > Le Sun, Aug 02, 2026 at 01:53:18AM -0400, obsd () mulh ! net wrote:
> > > cal | sed "1!s/`date +%e`\>/`tput so`&`tput se`/"
> > 
> > all those sed oneliners are fine and dandy but don't work with "cal 2026" :)
> 
> Extending it to parse the output of cal [year] is entirely plausible.

First, apologies to anyone sensitive to sed commands.

cal 2026 | sed "/`date +%B\ %Y`/,\${1!s/`date +%e`\>/`tput so`&`tput se`/;};
	/  `date +%Y`/,\${$(((10#`date +%m`-1)/3*8+5)),$(((10#`date +%m`-1)
	/3*8+10))s/^\(.\{$(((10#`date +%m`-1)%3*22)),$(((10#`date +%m`-1)
	%3*22+18))\}\)\(`date +%e`\)\>/\1`tput so`\2`tput se`/;}"

Line 1, Highlight day for (current) single month output.

Lines 2-4, Deal with (current) full year output.
Line 2, Selects the range of lines containing days for current month.
Line 3, Selects required indentation needed for current month's days.
Line 4, Highlights the current day using tput for standout codes.

Certainly not pretty and not efficient (runs date eight times) but works.
Don't ask for -j or -w support, this is long enough already.

On 2026-08-03 21:57:23, naddy () mips ! inka ! de wrote:
> Johannes Thyssen Tishman:
> 
> > I'm happy to hear other suggestions, but I can live without the feature
> > or with a shell alias as Crystal suggested.
> 
> FWIW, sysutils/ncal is a port of FreeBSD's extended cal(1) that has
> this feature by default.

Good Advice!

ncal -C
  or
ncal -Cy