Index | Thread | Search

From:
obsd@mulh.net
Subject:
Re: cal: add option to highlight the current day
To:
tech@openbsd.org
Date:
Mon, 17 Aug 2026 16:51:30 -0400

Download raw body.

Thread
  • obsd@mulh.net:

    cal: add option to highlight the current day

On 2026-08-05 20:05:24, I wrote:
> 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`/;}"

Not that anyone uses this but here's a shorter version.
Removes two date execs and three arithmetic expressions.
Still works for single month and full year cal outputs.

cal -y | sed "/`date +%B\ %Y`/,\${1!s/`date +%e`\>/`tput so`&`tput se`/;};
	/  `date +%Y`/,\${/`date +%B`/,/[^ ]\{4\}/s/^\(.\{$((2`date +%m`
	%3*22))\}.\{0,18\}\)\(`date +%e`\)\>/\1`tput so`\2`tput se`/;}"

Use as shown or concatenate to one line by removing newlines and tabs.
I couldn't post it as one line without having majordomo's line wrap ruining it.