Fd: Colorize matched substring like grep

Created on 9 Jan 2018  路  9Comments  路  Source: sharkdp/fd

Thanks a lot for fd, it's a really neat utility!

I'd like to kindly ask for a small feature addition: Please colorize the matched substring similar to how grep does it. I.e. compare the following two:

fd --color=always something
fd --color=always something | grep --color=always something

Ideally, the colorization of the second command would also be used for the first command.

Thanks

feature-request

Most helpful comment

Then I hope you re-evaluate your decision to abandon that change ;-)

All 9 comments

Thank you for the feedback!

Please see #46 and #53

Too bad this was abandoned :'( I'll probably have to make myself a wrapper than that uses grep like above. Feel free to close this then if you don't want to implement this.

Cheers

I'm happy to discuss this again, if there is an interest for this feature.

I don't think the grep wrapper will work as expected because

  1. grep will have to deal with the ANSI codes coming from fd - which will cause problems if you want to match across differently-colored segments
  2. ANSI colorings can not be nested. When grep adds additional reset-sequences after the match, it will reset fd's colorization prematurely.

The grep works for me. I mean sure, it loses the highlighting in parts of the path. But that's not as important to me as actually seeing the matched substring.

If this feature would be built-in to fd, it could close the previous ANSI code, highlight the substring, then reopen the previous ANSI code. I have zero knowledge of your code base, so I can't say how hard this is. Conceptually, I would personally solve it by delaying the highlighting until right before the output is written. I.e. keep a stack of highlighted ranges and then just add ranges there. Once you highlight, you can use that data to output the ANSI colorings as needed and simulate the nesting.

That's essentially what the prototype in #53 does.

Then I hope you re-evaluate your decision to abandon that change ;-)

+1

I don't see any strong support for this, so I'm going to close this for now (sorry).

Nooooo枚ooooo!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mwgkgk picture mwgkgk  路  3Comments

matu3ba picture matu3ba  路  4Comments

blueray453 picture blueray453  路  3Comments

sharkdp picture sharkdp  路  3Comments

mathomp4 picture mathomp4  路  4Comments