lscolors icon indicating copy to clipboard operation
lscolors copied to clipboard

Option to output colored file name only

Open nkh opened this issue 2 years ago • 7 comments

Given "aaa/bbb/entry" return only "color + entry + color reset".

Use case:

I have "$HOME/downloads", which happens to be a link, and a lot of other files from different directories in a list and want to colorize them.

The only way to get correct colorization is to be in the right directory for each entry in the list, this means starting a process for each entry and is prohibitively expensive.

I can send the full path but then I'd have to parse the colored string.

An alternative would be to output the colored path and the colored entry on different lines.

nkh avatar Dec 14 '23 20:12 nkh

Isn't this the same as https://github.com/sharkdp/lscolors/issues/70?

sharkdp avatar Dec 16 '23 16:12 sharkdp

@sharkdp

They are different.

issue 70

Add a user defined $root to every input entry

issue 78

output only the colored basename without the path

orthogonality

a list of files could be passed as arguments with --root $root to be added to the files and --name-only would only return the basename of the file colored according to the file present int $root (ie could exist and be executable in $root).

nkh avatar Dec 16 '23 16:12 nkh

You can do this with bfs:

$ bfs -color -prune -printf '%f\n' path/to/file1 path/to/file2
file1
file2

tavianator avatar Dec 16 '23 17:12 tavianator

@tavianator I would but

positive: bfs is faster than lscolors negative: bfs doesn't accepted files on stdin which is a show stopper for me

nkh avatar Dec 16 '23 17:12 nkh

If you can \0-separate them instead of \n, then it does support -files0-from -. If not, there's always xargs :)

tavianator avatar Dec 16 '23 18:12 tavianator

@tavianator

I didn't get that far in the man page.

I'll probably end up writing a wrapper called 'lscolors' around 'bfs' till I find the time to replace it, I just found out that I use lscolors in 25 different places in my code!

nkh avatar Dec 16 '23 18:12 nkh

See #80 for some changes related to this ticket.

sharkdp avatar Jan 16 '24 19:01 sharkdp