Fd: LS_COLOR

Created on 16 Nov 2018  路  12Comments  路  Source: sharkdp/fd

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

question

Most helpful comment

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.

All 12 comments

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

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.

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?

yes, like the ls_color command

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.

Hi everyone,

I would also need this kind of lib for my project lsd (Peltoche/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.

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

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

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 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.

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 => https://github.com/sharkdp/lscolors/issues/4

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ariecattan picture ariecattan  路  3Comments

mathomp4 picture mathomp4  路  3Comments

mwgkgk picture mwgkgk  路  3Comments

christianbundy picture christianbundy  路  3Comments

longcp picture longcp  路  3Comments