6

I want to emphasize holidays by color in cal or similar command.

I'm using OS X and Ubuntu 14, is there easy way to enable the function?

1 Answer 1

7

I don't think it is possible for standard cal, but you may want to take a look at gcal, the GNU calendar.

To highlight the text you need to pass -H option:

-H text
--highlighting=text
    Set highlighting sequence / marking character pairs explicitly.
    In this sense, highlighting sequences are control character sequences 
    which cause a color or intensity switch in output text. Typical control 
    character sequences are the ANSI escape sequences [...]

There is even exactly highlighting holidays example in the manual:

For example:

-H \x20:\x20:\x1:# respectively
--highlighting=\x20:\x20:\x1:#
marks the actual day like ‘\x20actual date\x20’6 and the holiday date like 
‘\x1holiday date#’ using the given marking characters. 

-H \x1b[34;42m:\x1b[0;40m or
-H \033[34;42m:\033[0;40m or
-H \E[34;42m:\E[0;40m
defines a starting ANSI escape highlighting sequence ‘\x1b[34;42m’ used for 
actual day and ending ANSI escape highlighting sequence ‘\x1b[0;40m’ with no 
given highlighting sequence for holidays, so default highlighting sequences for 
holidays are used (non-given entries are always skipped).

Example:

  • To highlight current day in blue, and holidays for United States/Alaska (US_AK) in green for current month:

    gcal -H '\e[34m:\e[0m:\e[32m:\e[0m' -q US_AK
    

    Note: 34 is ANSI code for foreground blue, and 32 is ANSI code for foreground green

    The results:

    enter image description here

  • To display current day in red (31) on green background (42) and Chinese (CN) holidays in yellow (33) on magenta (45) for whole 2014

    gcal -H '\e[31;42m:\e[0m:\e[33;45m:\e[0m' -q CN 2014
    

You will find all country codes in info gcal under description of -q option.

3
  • Thanks for answer, I installed gcal and try gcal -H "\033[34;42m:\033[0;40m", it changes appearance a bit, but there is no color. I'll try it later in Ubuntu.
    – ironsand
    Oct 28, 2014 at 7:01
  • 1
    @Tetsu I've updated the answer with examples, hopefully it is clear now.
    – jimmij
    Oct 29, 2014 at 21:51
  • Great! Now it works as I expected.
    – ironsand
    Oct 31, 2014 at 4:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .