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?
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.
Sign up to join this communityI 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:
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.