linux html css output follow,linux - Are there any options to let cat output with color? - Super Use...

博客介绍了如何通过AGNU package的source-highlight工具和lesspipe.sh脚本来增强cat命令,使其能够高亮显示代码。在Ubuntu上,可以使用apt-get安装。设置环境变量LESSOPEN和LESS后,只需运行ccat即可实现类似cat的功能但带有高亮。这个方法依赖于Boost regex库,并提供了在.bashrc中添加配置的步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

A GNU package, source-highlight, seems to do the trick (though isn't using cat -- as John T points out, this isn't possible with cat specifically). It's available via apt-get on Ubuntu, and requires the Boost regex library. Check your package manager to see if both are available, otherwise you can grab them from the web. The GNU page linked earlier has a link to Boost, I think.

After installation, I created a new script in my path called ccat. The script looks like:

#!/bin/bash

src-hilite-lesspipe.sh $1

Nothing fancy, just simplifying the less script they include with source-highlight. It acts just like cat when called in this fashion.

The included less script is a nice script to use as well, though. I just added the following to .bashrc:

export LESSOPEN="| /path/to/src-hilite-lesspipe.sh %s"

export LESS=' -R '

That script is included in the online manual for source-highlight, as well.

I guess you could alias cat to call src-hilite-lesspipe.sh $1 if you felt like ignoring cat altogether, but that might not be desirable.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值