Re: cal: add option to highlight the current day

[email protected]
Newsgroups gmane.os.openbsd.tech
Message-ID <[email protected]>
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.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.