Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Is it possible to set regex patterns for color matching in the LS_COLORS variable? So instead of just

*.jpg=38;5;220

Can I do

\.(jpg|gif)=38;5;220

That's just an example, I'd like to get more complicated than that. Am I asking too much from this? Is there another way to do terminal color schemes that I can get fancier?

I'm using zsh btw, so if I can do it there but not bash, that's fine.

share|improve this question
add comment

1 Answer

That's a feature of the ls utility in GNU coreutils. It doesn't depend on the shell. The syntax is not documented (you're supposed to use dircolors and figure it from there), but a quick look at the source shows that the only way to match files by name is to use * followed by a string which must be a suffix for a file name to match. The string is interpreted literally, except that \ and ^ introduce escape sequences (e.g. \n = ^J = newline).

So you can't match different extensions with the same pattern. But you can use shell programming constructs to build LS_COLORS:

for ext in jpg gif; do LS_COLORS="$LS_COLORS:*.$ext=38;5;220"; done
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.