如何在`cal`命令中按颜色强调假期

iro*_*and 6 cal

我想通过颜色cal或类似命令来强调假期。

我正在使用 OS X 和 Ubuntu 14,是否有简单的方法来启用该功能?

jim*_*mij 6

我不认为这是可能的标准cal,但你可能想看看gcal,在GNU日历

要突出显示您需要传递-H选项的文本:

-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 [...]
Run Code Online (Sandbox Code Playgroud)

手册中甚至有突出显示假期的例子:

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).
Run Code Online (Sandbox Code Playgroud)

例子:

  • 要以蓝色突出显示当前日期,并以绿色突出显示当前月份美国/阿拉斯加 (US_AK) 的假期:

    gcal -H '\e[34m:\e[0m:\e[32m:\e[0m' -q US_AK
    
    Run Code Online (Sandbox Code Playgroud)

    注:34前景蓝32为ANSI代码,前景绿为ANSI代码

    结果:

    在此处输入图片说明

  • 在整个 2014 年以红色 ( 31) 显示绿色背景 ( 42) 和CN黄色 ( 33) 洋红色 ( 45)节假日

    gcal -H '\e[31;42m:\e[0m:\e[33;45m:\e[0m' -q CN 2014
    
    Run Code Online (Sandbox Code Playgroud)

您将在选项info gcal说明下找到所有国家/地区代码-q