如何让cat支持高亮?
默认的 pygmentize -g {filename} 不太好看:

蓝色关键字和黑色背景混再一起看起来很累,因为默认高亮只使用 7 色,同时 8 字符宽度的 tabsize 看着也不大舒服。
给 pygmentize 加几个参数就好多了:
pygmentize -P style=monokai -P tabsize=4 -f terminal256 -g {filename}

漂亮清晰多了,style 可以自己换,最后封装成一个函数,放你的 .bashrc 里:
function ccat() {
local style="monokai"
if [ $# -eq 0 ]; then
pygmentize -P style=$style -P tabsize=4 -f terminal256 -g
else
for NAME in $@; do
pygmentize -P style=$style -P tabsize=4 -f terminal256 -g "$NAME"
done
fi
}
然后你就可以跟 cat 一样使用 ccat 命令了。
这里有 pygments 的 style 预览,选款你喜欢的把上面 style 换了:
编辑于 2018-03-01 22:04