export LS_COLORS :对以 README* 开头的每个文件应用规则 [英] export LS_COLORS : apply the rule for every file beginning by README*

查看:46
本文介绍了export LS_COLORS :对以 README* 开头的每个文件应用规则的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对以下规则有疑问.如果我这样做:

I have a problem with the following rule. If I do:

eval `/opt/local/libexec/gnubin/dircolors ~/.dircolors`
export LS_COLORS="${LS_COLORS}*README=00;37;44"

然后,当创建一个README文件时,我会得到:

Then, when creating a README file, then I will get:

但是现在,我想应用规则并对以 README 开头的每个文件名执行相同的操作(例如 README_somethingREADME_important).

But now, I would like to apply the rule and do the same for every filename beginning by README (like README_something, README_important).

为此,我尝试放置:

 export LS_COLORS="${LS_COLORS}*README*=00;37;44"

但没有如上图显示(只有白色).

but it is not displayed as above image (only white).

如何使用 LS_COLORS 管理通配符(我使用的是 MacOS Big Sur)?

How to manage the wildcards with LS_COLORS (I am on MacOS Big Sur)?

按照 user1934428 的建议,我尝试了:

Following user1934428's advice, I tried with:

export LS_COLORS="${LS_COLORS}:*README*=00;37;44"

不幸的是,例如,当我应用命令l"时,像 README_important 这样的文件名不会像上面的图片那样显示.这实际上是由以下定义的:

Unfortunately, for example, a filename like README_important doesn't display like my image above when I apply the command "l" which is actually defined by:

alias l='grc -es --colour=auto ls --color -Gh -C -lrt'

为什么不接受语法 README ?特别是,第二颗星应该扩展所有名为 README_somethingREADME_anything... etc

Why isn't the syntax README accepted ? especially, the second star which is supposed to expand all the files named like README_something, README_anything... etc

这是 $LS_COLORS 的值,一旦我打开一个新终端:

Here is the value $LS_COLORS, once I open a new terminal:

$ echo $LS_COLORS
no=01;37:fi=01;37:di=32:ln=01;36:pi=40;33:so=01;35:bd=40;33;01:cd=40;33;01:ex=00;36:*~=05;31:*.mtxt=05;31:*.ndx=05;31:*.cmd=00;33:*.exe=00;33:*.com=00;33:*.btm=00;33:*.bat=00;33:*.txt=00;37:*.pdf=04;94:*.docx=00;91:*.doc=00;91:*.xlsx=00;91:*.xls=00;91:*.c=00;35:*.h=00;35:*.sh=00;36:*.py=00;36:*.cpp=00;35:*.pl=00;36:*.pm=00;35:*.cgi=00;35:*.java=00;35:*.html=00;35:*.tar=00;31:*.tgz=00;31:*.arj=00;31:*.taz=00;31:*.lzh=00;31:*.zip=00;31:*.z=00;31:*.Z=00;31:*.gz=00;31:*.jpg=01;35:*.jpeg=01;35:*.JPG=01;35:*.gif=01;35:*.GIF=01;35:*.bmp=01;35:*.BMP=01;35:*.xbm=01;35:*.ppm=01;35:*.xpm=01;35:*.tif=01;35:*.png=01;35:*README*=00;37;44

我现在只有一个 ':' 字符.

I have now only one ':' character.

但这并不能解决最初的问题,即考虑到 README* 文件名的通配符.

But this doesn't solve the original issue, i.e the taking into account of the wildcard for README* filenames.

推荐答案

我在这里看到几个问题:

I see several problems here:

您显然假设 LS_COLOURS 已经有一个值,因为您对其进行了扩展.但是,LS_COLOURS 中的条目由冒号分隔,而您没有.

You obvously assume that LS_COLOURS already has a value, because you expand it. However, entries in LS_COLOURS are separated by a colon, and you don't have one.

另一个问题是顺序很重要:ls 一个接一个地解析条目,一旦找到匹配的条目,这就是它使用的颜色.因此,更具体的条目应位于颜色列表的开头.

The other problem is that sequence matters: ls parses the entries one after the other, as soon as it finds a matching one, this is the colour it uses. Therefore, more specific entries should be at the start of the colour list.

更新

我用我的 ls(GNU coreutils 8.26) 版本尝试了各种变体,发现诸如 *README* 之类的通配符模式将被忽略.唯一一种通配符模式是条目开始处的星号.因此,

I tried out various variations with my version of ls(GNU coreutils 8.26) and found that a wildcard pattern such as *README* would be ignored. The only kind of wildcard pattern is an asterisk at the start of the entry. Hence,

LS_COLORS='*README-txt=35;46'  /bin/ls --color=yes *README*

给我的文件着色x-README-txt,但是

LS_COLORS='*README*=35;46'  /bin/ls --color=yes *README*
LS_COLORS='*READ*-txt=35;46'  /bin/ls --color=yes *README*

不要.另外,我上面关于条目顺序的评论不正确.虽然顺序确实很重要,但更靠右的条目优先.因此,如果你有

don't. Also, my above remark about the sequence of entries was not correct. While sequence indeed does matter, entries further to the right take priority. Therefore, if you have

LS_COLORS='*txt=35,46:*t=32,44'  /bin/ls --color=yes *README*

文件 x-README-txt 将使用 32,44 着色.

the file x-README-txt would be colorized using 32,44.

这篇关于export LS_COLORS :对以 README* 开头的每个文件应用规则的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆