使用regex为输出着色
chromaterm的Python项目详细描述
色差
给终端的输出着色的工具。
关于
chromterm(ct
)从标准输入读取并根据用户可配置的规则对其进行着色。
想想像grep
这样的色标;把东西塞进里面就行了。然而,与其他行缓冲的程序不同,ct
与交互应用程序一起工作,比如ssh
。事实上,我有ssh() { /usr/bin/ssh $* | ct; }
在我的.bash_profile
中给我的会话加颜色。
下面是使用默认配置文件中的规则的示例:
安装
pip3 install chromaterm
If you have the legacy version of ChromaTerm, be sure to uninstall it first.
# If installed using HomeBrew brew uninstall chromaterm # If installed from source git clone -b legacy git@github.com:hSaria/ChromaTerm.git cd ChromaTerm--/src/ && ./configure && make uninstall
用法
默认情况下,chromterm读取主目录中的.chromaterm.yml
。例如,运行以下命令:
echo "Jul 14 12:28:19: Message from 1.2.3.4" | ct
During installation, the default config file was copied to home directory.
突出显示规则
所有突出显示规则都放在配置文件中的rules
数组下。下面是一个配置文件示例:
rules:-description:My first rule colors the foregroundregex:hello.+worldcolor:f#ff0000-description:Background this time, but just for "there"regex:Hey (there), buddycolor:b#ff0000group:1
说明
可选。纯粹是为了你。
正则表达式
使用的regex引擎是python的re。
颜色
颜色是十六进制字符串,前缀为b
表示背景(例如b#123456
)和f
表示前景(例如f#abcdef
)。
你可以用空格分隔前景和背景,比如b#123456 f#abcdef
。
组
可选。默认情况下,整个匹配都是彩色的。可以更改为regex
中的特定组。
帮助
如果你有任何问题或建议,请打开一个问题(一直感激)。