You are not logged in.

#1 2018-09-14 11:12:10

DCieD
Member
Registered: 2018-09-08
Posts: 9

[SOLVED ]LS_COLORS variable / set colors for certain kind of files

Hi,

when doing an *ls* it shows me the output in certain different colors. Now, I do know there is a possiblity to change colors for, say *.mp3 files.

However I want to set a color for a certain set of files, my work-files. Those files are video-files, pictures and text-files. Now I want all of these
"work-files" to have the same color, disregarding what file-types they are. so that I can quickly have an overview of the work-files in my desktop-folder
(where all sorts of stuff lives and then get sorted)

Now does anybody know how to make sure that these files are e.g. red...while other pictures and videos follow a different coloring scheme?

Thanks for helping out.

Last edited by DCieD (2018-09-15 07:51:17)

Offline

#2 2018-09-14 13:33:57

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,532
Website

Re: [SOLVED ]LS_COLORS variable / set colors for certain kind of files

How is `ls` supposed to know what you would consider a "work file"?  You've not outlined any criteria at all, except that some files are and some arent.  The answer is to edit dircolors, but how to edit it (and whether it's possible with ls directly) depends entirely on what your criteria are.

(edit: though dircolors itself gives *very* few options other than the extension, so it will not likely suffice).

If you had a list of the files, you could make a new ls function which would set an (otherwise unused) attribute to the files in that list, run /bin/ls, then unset that attribute again and just set LS_COLORS/dircolors to color files with that attribute red.

Or perhaps you could put the full list of files into dircolors - this would risk some false positives though for any non-work file with a name that ended in something that matched a work file (e.g., if you have a file "work1.doc" and another "nonwork1.doc" they'd both be colored red).

Last edited by Trilby (2018-09-14 13:45:39)


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#3 2018-09-14 14:18:41

DCieD
Member
Registered: 2018-09-08
Posts: 9

Re: [SOLVED ]LS_COLORS variable / set colors for certain kind of files

Thank you, well of course of you are correct...the files all have certain naming scheme..say, date_work_01.png / date_morework_02.mkv...so any file with a date and the word "work" and "morework"
shall be colored red. the names "work" and "morework" dont change.  Only "date" changes of course and the number in the end.

if for some reason another file also has the words "work" or "morework" in it's title (which is unlikely) I could live with that. but of course it would be much better if only the files with that exact naming-scheme would
be colored red.

I hope you can understand me. I'm not native english speaking. sorry

thank you.

Offline

#4 2018-09-14 14:36:39

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,532
Website

Re: [SOLVED ]LS_COLORS variable / set colors for certain kind of files

About how many numbers would there be (e.g., date_work_01.png, date_work_02.png ...)?

Would it be possible to change the naming scheme slightly to date_01_work.png, date_02_work.png ...?

If there is either a small number of different numbers, or even better if you chould change the naming scheme to put the number before "work", then you could easily do this with dircolors/LS_COLORS with entries like:

work.png 31
work.mkv 31
work.doc 31
work.pdf 31
# and more for each likely "work" filetype

This way any file ending in "work.png" and the like would be colored red.  There is no real meaning to an 'extension', dircolors just matches against the end of a filename.

Of course, you could also just make aliases of ls to either hide or only show the 'work' files, then not worry about changing the color:

alias ls='/bin/ls --hide=*work*'
alias work_ls='/bin/ls *work*'
# or vice versa if you'd prefer to show work files as the default

Last edited by Trilby (2018-09-14 14:39:26)


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#5 2018-09-15 07:48:22

DCieD
Member
Registered: 2018-09-08
Posts: 9

Re: [SOLVED ]LS_COLORS variable / set colors for certain kind of files

Hi,

thank you very much. That solved my question. So looked into "dircolors" as suggested by you and looked into it.
Then I created a file in in my home called .dircolors with this command

dircolors -p > ~/.dircolors

openend it with vim and could easily edit the colors there, and I added the pattern of my work-file-names, like you suggested, thanks for that, I didnt think about it

Then just put that line into the zshrc

echo 'eval "$(dircolors -b ~/.dircolors)"' >> ~/.zshrc

and it works flawless. now I can turn off all the coloring when doing an ls, that I dont need plus when doing stuff in my Desktop Folder (where all sorts of garbage piles up during the week), I still have my work-files colored
and that indicates that they are still there and need some love.
Thanks for your help

Offline

Board footer

Powered by FluxBB