5

In Ubuntu and Fedora, when I type cal on the command line I get an ASCII calendar with the current day highlighted.

In OSX, when I type cal, I get an ASCII calendar but no day is highlighted.

How can I get the highlighting of the current date in OSX?

merlin2011
  • 3,855
  • 5
  • 27
  • 36
  • OSX and Linux use different implementations of cal. I imagine OSX's isn't written to highlight the current day. – Andy Dalton Aug 24 '15 at 21:36
  • @AndyDalton, I just noticed after your comment that OSX's version is 5 years older (2004 vs 2009) based on the man page. – merlin2011 Aug 24 '15 at 21:43
  • 1
    @merlin2011 OS X uses “BSD cal” while Linux will be using “GNU cal”. Two different implementations rather than versions – forquare Aug 24 '15 at 21:47

2 Answers2

4

I've tried ubuntu, fedora, slackware, and netBSD and all the cal's automatically highlight the current day. However, I know some cals don't auto highlight, and either way, this does work:

cal | grep -C 6 --color -e " $(date +%e)" -e "^$(date +%e)"

Although I can't test on OS X as I do not have access to it.

Klaatu von Schlacker
  • 3,028
  • 13
  • 15
2

The following prints the current date with a reversed field which is replaced in cal by sed.

ptd=$(date -j +%d)
ctd=$(printf "\033[0;7m"$ptd"\033[0m")
cal | sed 's/'"$ptd"'/'"$ctd"'/'
fd0
  • 1,430
  • 1
  • 10
  • 14
  • Replace the sequences of escape codes with (the output of) `tput smso` and `tput rmso` and you'll have something that works correctly when it's piped to a file, or even used on a different type of terminal. – roaima Aug 24 '15 at 22:28
  • Does not work for single digit dates. Example: today, `date -j +%d` prints `04` which does not appear in output of `cal`. – Wildcard Oct 04 '17 at 07:05