sharkdp / lscolors

A Rust library and tool to colorize paths using LS_COLORS
Apache License 2.0
265 stars 18 forks source link

Add an option to style any string without path verification #80

Closed REALERvolker1 closed 10 months ago

REALERvolker1 commented 11 months ago

This pull request adds a function, LsColors::style_for_str() that retrieves the correct suffix style for any string.

It would provide a workaround for both #70 and #78, they would just have to verify that the file exists before colorizing it. Or, they could just colorize it, because that would work too.

It's pretty simple anyways. I decided not to implement this in bin.rs because I did not know if you want that or not.

Let me know if I need to revise anything. I tried to keep changes minimal, and this was literally the second rust #[test] I've ever written.

sharkdp commented 10 months ago

Thank you very much for your contribution. I rebased to fix some CI issues and did a minor rewrite of the unit test — hope that's fine with you.

Regarding the lscolors binary, let's discuss potential changes in the two issues you linked above. I'm certainly open to that.

nkh commented 10 months ago

@sharkdp it would be great if the option existed in the binary.

Best would be to color normally if the file exists (executable bit, ...) or just color it according to the extension otherwise.

sharkdp commented 10 months ago

Can you please open a new issue with a proposal on how we would change the CLI (if necessary)?