Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show file is binary also in -p mode #530

Closed
mjarkk opened this issue Mar 22, 2019 · 11 comments
Closed

Show file is binary also in -p mode #530

mjarkk opened this issue Mar 22, 2019 · 11 comments
Labels
feature-request New feature or request good first issue Good for newcomers

Comments

@mjarkk
Copy link

mjarkk commented Mar 22, 2019

I currently use bat as cat replacement but because bat uses line numbers and file notations i added the -p flag in my fish config:

function cat
  bat -p $argv
end

This works great but i noticed there is no output when i bat over binary files.
yes i know that this is totally useless but this confuses me sometimes with thinking that it's just an empty text file.

It would be nice to get some feedback like cat where it shows a corrupted output or let it say something like <BINARY> the same as without -p

@mjarkk mjarkk changed the title Show "<BINARY>" also in -p mode Show file is binary also in -p mode Mar 22, 2019
@sharkdp
Copy link
Owner

sharkdp commented Mar 22, 2019

Thank you for the feedback. The <BINARY> message is part of bats header, so currently it is only present if --style=header (or some style including the header) is used.

But your requests sounds sensible to me. I think I'm okay with printing <BINARY> when --plain is used (and of course only when we are in interactive mode, i.e. when the output is not piped).

@sharkdp sharkdp added feature-request New feature or request good first issue Good for newcomers labels Mar 22, 2019
@mjarkk
Copy link
Author

mjarkk commented Mar 22, 2019

That would be nice addition.

@VitorVRS
Copy link

This seems odd to me. If you are using plain mode, the default behavior should print the whole file contents (even if binary, I think).
Don't know if there are use cases, but bat can't print a binary file.

@mjarkk
Copy link
Author

mjarkk commented Apr 15, 2019

bat can print binary but only when piped from bat bat someBinFile | /bin/cat
And to me that seems to be the only need for binary files also people think the same from prior issues.

But i can see a use case of binary data, for example:
A encrypted message with at the end some meta data about the encrypted content in utf8.
If someone would cat over the file it would see the meta data of that file at the end.

Showing it a binary file also might confuse someone with thinking is a file with the contents of <BINARY>

@VitorVRS
Copy link

bat can print binary but only when piped from bat bat someBinFile | /bin/cat

Use just cat then ¯\_(ツ)_/¯

So, SHOULD plain mode print the binary content or SHOULD print <BINARY>?

@mjarkk
Copy link
Author

mjarkk commented Apr 16, 2019

I would prefer showing <BINARY> over outputting binary data.
But it does need to be obvious for a user that bat shows it's a binary file and not a text file with that text.

I think just showing <BINARY> makes the application look a bit more "modern" most users don't need more information that the information of the file being binary.
Dumping the binary data makes a application look a bit old and there are already other much better tools for viewing binary data. If someone really wants to view binary data they can also just do: bat fileName | cat.

I'm interested in @sharkdp opinion about this.

@maxfilov
Copy link

maxfilov commented Apr 19, 2019

I would like to implement this one, actually.

There are two different views on

─────┬──────────────────────────────────────
     │ File: bat   <BINARY>
─────┴──────────────────────────────────────

bat sees it as a decoration to binary file and doesn't print contents of the binary file at all. The -p switches off all decorations by default therefore you don't see the header. On the other hand user thinks that this is a special treatment of the file. Like, if this is a binary, bat will say that by printing out <BINARY>.

From my point of view, if we want <BINARY> to be printed out when the decorations are turned off by the -p switch, then bat should consider <BINARY> not as the decorations, but a special binary file treatment and always print <BINARY> to the terminal. For example -n switch also turns the decorations off and if we amend behaviour of the -p => we amend -n as well.

Printing of the contents in -p mode is not an option I think, 'cause -p means "turn off decorations" not "print all which you don't print in normal mode"
@mjarkk @sharkdp @VitorVRS

@maxfilov
Copy link

maxfilov commented Apr 27, 2019

I think that the best way to fix this is to replace the contents of binary files with <BINARY> instead of nothing. @sharkdp

This actually raises another question, why bat iterates over whole binary file if it doesn't prints the contents. If I do something like bat executable and the executable is 300mb then bat will be iterating over the whole file. Is there a reason for that?

@sharkdp
Copy link
Owner

sharkdp commented May 14, 2019

This actually raises another question, why bat iterates over whole binary file if it doesn't prints the contents. If I do something like bat executable and the executable is 300mb then bat will be iterating over the whole file. Is there a reason for that?

Hm, maybe this should be addressed in another ticket.

@sharkdp
Copy link
Owner

sharkdp commented May 14, 2019

closed via #550 by @maxfilov.

bat now has this behavior:
image

@sharkdp
Copy link
Owner

sharkdp commented May 15, 2019

This is included in v0.11.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

4 participants