ccat让cat命令有颜色的输出
众所周知,cat(concatenate)命令是一个用于查看、合并和复制文本文件的Unix命令,这个命令是GNU/Linux和类Unix操作系统中每天最常用的命令之一。如果你经常使用cat命令,那么你可以尝试一下'Ccat'。它与cat命令非常相似,ccat会显示带有语法高亮显示的内容。目前支持的语言是JavaScript,Java,Ruby,Python,Go,C和JSON。
安装
[root@py data]# wget --no-check-certificate https://github.com/jingweno/ccat/releases/download/v1.1.0/linux-amd64-1.1.0.tar.gz # github官方下载
[root@py data]# wget --no-check-certificate https://dl.lianst.com/%E5%BC%80%E6%BA%90%E8%BD%AF%E4%BB%B6/ccat/linux-amd64-1.1.0.tar.gz # 国内下载
[root@py data]# tar -zxvf linux-amd64-1.1.0.tar.gz
[root@py data]# cp linux-amd64-1.1.0/ccat /usr/local/bin/
[root@py data]# chmod +x /usr/local/bin/ccat
用法
ccat和cat的用法大相径庭,详细的帮助信息可以help一下。
[root@py data]# ccat --help
Colorize FILE(s), or standard input, to standard output.
Usage:
ccat [OPTION]... [FILE]...
Flags:
--bg="light": set to "light" or "dark" depending on the terminal's background
-C, --color="auto": colorize the output; value can be "never", "always" or "auto"
-G, --color-code=: set color codes
-h, --help=false: help for ccat
--html=false: output html
--palette=false: show color palettes
-v, --version=false: show version
Using color is auto both by default and with --color=auto. With --color=auto,
ccat emits color codes only when standard output is connected to a terminal.
Color codes can be changed with -G KEY=VALUE. List of color codes can
be found with --palette.
Examples:
$ ccat FILE1 FILE2 ...
$ ccat --bg=dark FILE1 FILE2 ... # dark background
$ ccat --html # output html
$ ccat -G String="_darkblue_" -G Plaintext="darkred" FILE # set color codes
$ ccat --palette # show palette
$ ccat # read from standard input
$ curl https://raw.githubusercontent.com/jingweno/ccat/master/main.go | ccat
基本使用和cat都是一样的
[root@py linux-amd64-1.1.0]# ccat LICENSE
从上面的图片中,你应该有注意到它们之间的区别了。ccat使用语法高亮显示输出,而cat命令只是以系统的默认主题颜色显示输出。
ccat也可以显示多个文件的输出
[root@py linux-amd64-1.1.0]# ccat LICENSE README.md
或许在某些时候你可能想让让它直接以html的格式输出,这样也是可以的。
[root@py linux-amd64-1.1.0]# ccat LICENSE --html
ccat不单单能显示本地的文件,也可以显示在线(网络)文件。
[root@py linux-amd64-1.1.0]# curl https://raw.githubusercontent.com/jingweno/ccat/master/main.go | ccat
显示默认的ccat颜色配置
自定义输出的颜色和字体
[root@py linux-amd64-1.1.0]# ccat -G String="_darkblue_" -G Plaintext="darkred" LICENSE
如果你觉得ccat非常好用的话,也可以alias cat='/usr/local/bin/ccat
的。
- 上一篇: 纪念服务器稳定运行200天
- 下一篇: [Python笔记] locals() 函数