fd icon indicating copy to clipboard operation
fd copied to clipboard

Implement option for printing custom formats

Open tmccombs opened this issue 2 years ago • 10 comments

This is mostly a proof of concept before merging there is still some work that needs to be done for:

  • [x] Write new tests (both unit tests and integration tests)
  • [x] Add documentation to man page
  • [ ] Potentially add support for outputting arbitrary bytes on unix like we do for normal printing
  • [ ] Benchmark, and optimize if necessary
    • one potential optimizaiton could be to write directly to the stream rather than creating building an intermediary OsString, I started looking into that, but it got kind of messy.

Also, this doesn't currently support colorized output when using format string. I thing that for an initial implementation that is probably fine.

tmccombs avatar Jun 16 '22 07:06 tmccombs

Thank you very much for taking a stab at this!

I didn't have time to properly review it, but I think I am in favor of integrating this new option! That is, unless it leads to a performance penalty for the default case (without --format).

Something that I thought about in a different context, but seems fitting here: I'm not a huge fan of the {}/{/}/{//}/{.}/… syntax, which we borrowed from GNU parallel, I believe. Would it make sense to think about something a bit more verbatim? I think we could easily support something like {path}/{basename}/{parent}/{without_extension}/… in addition. What do you think? I'd much rather type out those words than having to look up the syntax each time.

sharkdp avatar Jul 11 '22 20:07 sharkdp

I like the more verbose names too.

tmccombs avatar Jul 12 '22 00:07 tmccombs

:+1:. We can also do this in a follow up PR though.

sharkdp avatar Jul 12 '22 20:07 sharkdp

Regardless of the short/long syntax discussion, I'd like to see this being integrated to fd!

@tmccombs Are you still interested in finishing this? It would probably be best to focus on the benchmarks first, to make sure that we don't run into performance regressions.

sharkdp avatar Sep 11 '22 19:09 sharkdp

Sorry it took me so long to get back to this. I am interested in finishing this. Though I wouldn't mind some help with benchmarking it.

tmccombs avatar Dec 24 '22 07:12 tmccombs

It would be great to pick this up again. Anything I can do? I can definitely take care of the benchmarks. I could also take a look at fixing the merge conflicts (?).

sharkdp avatar Dec 08 '23 13:12 sharkdp

I fixed the merge conflicts.

One question I have is if we would rather have a --printf option with more format optiions, such as access and modified times, owning user and group, etc. Certainly not as extensive as find, but more than just variants of the path. Although, I really don't love the idea of having two different format syntaxes.

tmccombs avatar Dec 09 '23 09:12 tmccombs

One question I have is if we would rather have a --printf option with more format optiions, such as access and modified times, owning user and group, etc. Certainly not as extensive as find, but more than just variants of the path. Although, I really don't love the idea of having two different format syntaxes.

I would personally like if we extend the {…} syntax. For example, we could have more descriptive aliases like {basename} instead of {/}. This would allow us to use something like {access_time} and similar if we want to add more fields, without having to come up with a cryptic/concise syntax. If we need more control over how a field like a date is printed, we could follow Python f-strings syntax with something like {access_time:%Y-%m-%d}. I don't think that we need to have a find -printf compatibility mode here. What do you think?

sharkdp avatar Dec 13 '23 12:12 sharkdp

That sounds good to me.

tmccombs avatar Dec 13 '23 20:12 tmccombs

@tmccombs @sharkdp - Any chance this will be merged soon?

I'm dying for this feature and compulsively checking this PR every few days as a result. Please put me out of my misery lol.

cohml avatar Jan 21 '24 13:01 cohml