Only list text files (i.e., exclude binaries) #749
Comments
|
How do you define a text file? A file that only contains ASCII characters? Only valid UTF-8 sequences? It has a text/* MIME type? All of those would be kind of expensive to calculate. And determining the MIME type would be tricky to do in a portable way. |
|
@tmccombs commented on Mar 23, 2021, 11:31 PM GMT+4:30:
The heuristic commonly employed is to scan for NUL characters. It can fail (e.g., when I was storing NUL-separated strings in a text file in git), but it's good enough. |
|
I needed this functionality recently to pipe to output to fzf (with previews enabled)
Though it has a significant performance overhead |
you might want to try using rg (ripgrep) instead such as |
I wrote a blog post on this topic once |
|
I think this should be relatively easy to implement, if someone wants to try this. But please note that I'm not 100% sure that we want to add this to |
|
Hi, I'd like to give this a crack. I'm fairly new to Rust and open source in general, so I have a few questions:
If this is implemented using the If the To implement this behaviour, I think the I'm not that well versed in Rust, and definitely not familiar with this crate, so I quite possibly have missed something or made some incorrect assumptions. |
Probably the first n bytes, so that it isn't really slow if there are large files. |
I agree with @tmccombs. We should probably do something similar to
Hm, yes. But note this section: Lines 69 to 71 in 42dce35
I think we could open one of the generated test files and either write some text to it, or some "binary" content (i.e. something with
Okay. And we definitely want to make sure to only run the binary-check if either |
|
Before you invest too much time into this, maybe we should reconsider if we REALLY want to integrate this in |
|
If you're okay with $ fd -t f -X grep -lI .which will print the names of all non-binary, non-empty files. I hoped that a zero-length pattern like |
|
Initially, I had export FZF_DEFAULT_OPTS='--preview "bat --style=numbers --color=always --line-range :500 {}"'
export FZF_DEFAULT_COMMAND='fd --type f'in my config file and whenever I use fzf, I would get some binary files in the list (which were not a big problem but just an inconvenience). However, as I get comfortable with both fzf and fd I decided to skip the binary file check. Because most of the time I have a rough idea of what I am searching for and quickly filtering the files is better. |
|
@furkanusta If you are using (a recent version of)
|
|
I know, that is why I said it was more of an inconvenience rather than a problem. Since I am rarely interested in binary files I didn't want to see even the warning. |
|
How about we use |
I want an option to only list text files (i.e., exclude binaries).
The text was updated successfully, but these errors were encountered: