Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support more dircolors keys #6

Closed
8 of 10 tasks
tavianator opened this issue Dec 17, 2018 · 9 comments
Closed
8 of 10 tasks

Support more dircolors keys #6

tavianator opened this issue Dec 17, 2018 · 9 comments
Labels
help wanted Extra attention is needed

Comments

@tavianator
Copy link
Contributor

tavianator commented Dec 17, 2018

Right now it supports the ones based on file types. But there's also

  • ca for files with capabilities set
  • do for doors (some Solaris thing)
  • fi for regular files
  • mh for files with multiple hard links
  • no the "normal" color which acts as a fallback
  • ow for directories writable by other users
  • su for setuid files
  • sg for setgid files
  • st for sticky files
  • tw for sticky directories that are writable by other users
@sharkdp
Copy link
Owner

sharkdp commented Dec 17, 2018

Thank you for the feedback. Sounds good! We should try to support all of these (if feasible / possible).

@sharkdp
Copy link
Owner

sharkdp commented Jan 7, 2019

Do you know how ls treats multiple matches?

What if a file is both executable (ex) and has multiple hard links (mh)?

@tavianator
Copy link
Contributor Author

tavianator commented Jan 7, 2019

My version of the logic in C, in file_color(): https://github.com/tavianator/bfs/blob/master/color.c#L371.

In particular, ex seems to supersede mh if ex is set. But if ex is unset or zero, then mh applies.

I'm currently cooking up a test script that compares my version against the output of ls, so there may be some differences in corner cases, but I've tested a lot of it by hand and it seems to behave the same.

@sharkdp
Copy link
Owner

sharkdp commented Jan 7, 2019

Thank you very much for sharing your implementation!

So I guess there is no real specification on how LS_COLORS is intended to work, as you also seem to use the ls implementation as your reference.

@tavianator
Copy link
Contributor Author

Yeah the spec is the implementation AFAIK ;)

There's man dir_colors on Linux which specifies some details like

       ORPHAN color-sequence
              Specifies the color used for an orphaned symbolic link (one
              which points to a nonexistent file).  If this is unspecified,
              ls will use the LINK color instead.

but it doesn't tell you details like the relative priorities of things like su, sg, ex, etc.

@sharkdp sharkdp added the help wanted Extra attention is needed label Jan 20, 2019
@trapd00r
Copy link

Hey,
I'm trying to implement the same thing in my File::LsColor library and I wonder if this really can be implemented in a good way that doesn't take away any usefulness of our modules.
When I use it myself I don't always care for if the files do exist or not, or where in the filesystem they reside. I might only be interested in the basenames, and given for example:

ls_color

the filenames are relative and you can't stat them, thus you can't decide if they are directories, executables or anything else. (In this simple example I know what they are, but you get the point).

If we want to implement all of these extra keys, we would need to always get absolute paths as input which I don't think is feasible.

Thoughts?

@sharkdp
Copy link
Owner

sharkdp commented Jan 25, 2019

If I understand you correctly, the question is not really about relative or absolute paths, but rather about whether LS_COLORS-based colorization makes sense for paths which we can not stat for some reason (might be a made up filename, a relative path where we do not know the origin, a path on a remote system, etc.).

In my understanding, there are two steps in the LS_COLORS colorization.

  1. Metadata-based colorization (for directories, symlinks, executable files, etc.)
  2. If none of the patterns from step 1 apply, use a filename-suffix based loopkup (e.g. colorize *.flac files in a specific way)

lscolors is definitely designed in such a way that we always perform step 1 first, i.e. we need to have the filesystem metadata (unless it's actually a "missing" file). On the other hand, I can see how it could be useful to have a public method that would allow a suffix-based lookup without performing step 1.

@trapd00r
Copy link

I made the first step configurable with a simple binary on/off switch, because of

tavianator added a commit to tavianator/lscolors that referenced this issue Sep 16, 2021
sharkdp pushed a commit to tavianator/lscolors that referenced this issue Oct 3, 2021
tavianator added a commit to tavianator/lscolors that referenced this issue Oct 3, 2021
tavianator added a commit to tavianator/lscolors that referenced this issue Oct 3, 2021
sharkdp pushed a commit that referenced this issue Oct 8, 2021
@sharkdp
Copy link
Owner

sharkdp commented Feb 13, 2022

I believe this can be closed. I don't expect that anyone will miss do and ca. Otherwise, please let me know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants