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

LS_COLOR #363

Closed
nkh opened this issue Nov 16, 2018 · 12 comments · Fixed by #370
Closed

LS_COLOR #363

nkh opened this issue Nov 16, 2018 · 12 comments · Fixed by #370
Labels

Comments

@nkh
Copy link

nkh commented Nov 16, 2018

Hi,

Could you consider releasing an ls_color utility that does the coloring without the finding?

There is a perl ls_color but it does not work as advertised and is also slower

@sharkdp
Copy link
Owner

sharkdp commented Nov 18, 2018

What exactly are you looking for? What would this utility do? How would you like to use it?

@nkh
Copy link
Author

nkh commented Nov 18, 2018

Today I use ls_color to color files I display, be it when I "find" them or "grep" for them in divers bash scripts.

the problem with ls_color is that it does half of what ls does, executables, link, ... are not colorozed properly.

I am thinking of a command line too that can be used in a pipeline of course. In a list of files to colorize and out colored files

A few options that I can think about is ':

take full path in and output either:

  • fullpath and file name colored together
  • fullpath colored and only filename colored on the output
  • although I do not need it, but for completeness, output the input, the colored path, the colored file name in a columnized fashion so people can "cut" and pick what they want, and maybe even output the length of path without the coloring

the usual options, -0 -separator -a, etc...
and maybe:
-path_only
-name_only
-length (of non colorized element)
...

If you have everything at hand and want to do it, it would be nice, I'll otherwise write some perl module when I find time.

@tmccombs
Copy link
Collaborator

So if I understand correctly, this would mean factoring out the code to colorize output (including figuring out which color to use for what) into a separate library, and then build a seperate application that reads a list of files from stdin and then prints colorized output to stdout?

@nkh
Copy link
Author

nkh commented Nov 19, 2018

yes, like the ls_color command

@sharkdp
Copy link
Owner

sharkdp commented Nov 19, 2018

Even though this is not really related to fd, I think that's a good idea. I also thought that the LS_COLORS-functionality could be useful to other tools. Writing a small utility on top of this library should be really easy.

@Peltoche
Copy link

Peltoche commented Dec 8, 2018

Hi everyone,

I would also need this kind of lib for my project lsd (lsd-rs/lsd#28). @nkh do you have started anything? If not I think I will propose a lib based on your code in the next days/week.

@nkh
Copy link
Author

nkh commented Dec 8, 2018

@Peltoche No I haven't as I use lscolor from https://github.com/trapd00r/File-LsColor which does most of what I want.

@sharkdp
Copy link
Owner

sharkdp commented Dec 8, 2018

I have already started to work on this. I'll report back soon.

@sharkdp
Copy link
Owner

sharkdp commented Dec 9, 2018

I have published a first version of the lscolors crate:

Repo: https://github.com/sharkdp/lscolors
Crate: https://crates.io/crates/lscolors
Docs: https://docs.rs/lscolors/0.1.0/lscolors/

@nkh This also includes a lscolors utility (which you can download here) that is quite fast (around 3µs per path for my LS_COLORS variable with ~300 entries)

@Peltoche I'd be very happy to get your feedback (best way would be the new repo). I'm very open to API changes and other suggestions.

sharkdp added a commit that referenced this issue Dec 9, 2018
Use my new [lscolors](https://github.com/sharkdp/lscolors) crate instead
of the internal `lscolors` module

- Speeds up `LS_COLORS` querying, leading to a nice 25% performance
  improvement when
- Adds support for 24-bit colors and background colors

closes #368
closes #363
@nkh
Copy link
Author

nkh commented Dec 14, 2018

@sharkdp good job, I have integrated it in my perl script and works like a charm.

Now my script gets a bunch of paths and splits them to color the path and the files separately, because I want both colors, but if a "path/file.ext" is given to lscolors, the whole thing gets colored like "file.ext". I don't know if it is what you want.

Another point, which may make is useful for more people is to accept input as arguments (in addition to) getting input from stdin.

@sharkdp
Copy link
Owner

sharkdp commented Dec 14, 2018

Now my script gets a bunch of paths and splits them to color the path and the files separately, because I want both colors, but if a "path/file.ext" is given to lscolors, the whole thing gets colored like "file.ext". I don't know if it is what you want.

That is expected, for now. The library only provides a "get ANSI style for a given path" function. However, for the binary, we could think about supporting the fd-style of colorizing paths.

Another point, which may make is useful for more people is to accept input as arguments (in addition to) getting input from stdin.

Great idea => sharkdp/lscolors#4

@sharkdp
Copy link
Owner

sharkdp commented Dec 14, 2018

I'm going to close this ticket. Please post further feedback / feature requests as tickets in the lscolors repo: https://github.com/sharkdp/lscolors

@sharkdp sharkdp closed this as completed Dec 14, 2018
sharkdp added a commit that referenced this issue Dec 14, 2018
Use my new [lscolors](https://github.com/sharkdp/lscolors) crate instead
of the internal `lscolors` module

- Speeds up `LS_COLORS` querying, leading to a nice 25% performance
  improvement when
- Adds support for 24-bit colors and background colors

closes #368
closes #363
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants