所以我知道有一种方法可以更改目录、常规文件、bash 脚本等的文本颜色。有没有办法根据_file extension_?
例子:
$ ls -l
foo.txt [is red]
foo.text [is blue]
foo.secret [is green]
foo.txt [is red]
Run Code Online (Sandbox Code Playgroud)
是的,使用LS_COLORS变量(假设 GNU ls)。操作它的最简单方法是使用dircolors:
dircolors --print-database > dircolors.txt
Run Code Online (Sandbox Code Playgroud)
将当前设置转储到dircolors.txt,然后您可以对其进行编辑;添加设置后,
eval $(dircolors dircolors.txt)
Run Code Online (Sandbox Code Playgroud)
将更新LS_COLORS并导出它。您应该将其添加到您的 shell 启动脚本中。
要应用您提供的示例设置,要添加的条目dircolors.txt将是
.txt 00;31
.text 00;34
.secret 00;32
Run Code Online (Sandbox Code Playgroud)