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
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).
That would be nice addition.
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.
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>
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>?
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.
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
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?
This actually raises another question, why
batiterates over whole binary file if it doesn't prints the contents. If I do something likebat executableand theexecutableis 300mb thenbatwill be iterating over the whole file. Is there a reason for that?
Hm, maybe this should be addressed in another ticket.
closed via #550 by @maxfilov.
bat now has this behavior:

This is included in v0.11.0.
Most helpful comment
I would like to implement this one, actually.
There are two different views on
batsees 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,batwill 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, thenbatshould 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