sharkdp / bat

A cat(1) clone with wings.
Apache License 2.0
48.41k stars 1.2k forks source link

How do I make `bat` use `LF` and `^D` on Windows, similar to `cat` on Linux instead of `CRLF` and `^Z`? #2889

Open 500-internal-server-error opened 5 months ago

500-internal-server-error commented 5 months ago

The app description says "A cat(1) clone", so I expected it to behave like cat more :)

GNU coreutils cat, whether natively on Linux or through emulation such as Cygwin/MSYS2 on Windows, always uses LF characters, and when doing cat | hexdump -Cv, it waits for ^D before terminating.

On Linux, bat behaves as I expect, using LF and waiting for ^D when cating to hexdump. On Windows, however, it uses CRLF and waits for ^Z instead.

I doubt there is a setting somewhere to change this, but it would be great if I could be pointed to where to patch my local install of bat to behave more like GNU coreutils cat on Windows.

Thanks in advance.

RivenSkaye commented 2 months ago

GNU cat always using LF is a bug by definition. POSIX allows systems to define their own <newline> which is CRLF on Windows; but somehow cat accepts text files that end in incomplete lines more easily than files and environments that aren't exclusively \n.

That said, configurable behavior for bat output would be bliss

500-internal-server-error commented 2 months ago

In the meantime I learned that the LF and ^D behavior of cat on Windows is entirely due to Cygwin's cygwin1.dll and MSYS2's msys-2.0.dll, deep in the Unix environment emulation dark magic. So I don't think it can be a "userland" config without essentially recreating Cygwin somewhere down the line, probably inside Rust.

One can certainly dream though :)