top | item 45640678

Bat v0.26.0

149 points| indentit | 4 months ago |github.com

74 comments

order

oneeyedpigeon|4 months ago

The `--pager=builtin` change is interesting; first time I've heard of minus.

> Traditional pagers like more or less weren't made for integrating into other applications. They were meant to be standalone binaries that are executed directly by users. However most applications don't adhere to this and exploit these pagers' functionality by calling them as external programs and passing the data through the standard input.

Do people widely agree with this? That sounds less like 'exploitation' to me and more like 'the way Unix works'.

> This method worked for Unix and other Unix-like OSs like Linux and MacOS because they already came with any of these pagers installed. But it wasn't this easy on Windows; it required shipping the pager binary along with the applications. Since these programs were originally designed for Unix and Unix-like OSs, distributing these binaries meant shipping an entire environment like MinGW or Cygwin so that these can run properly on Windows.

So, to support Windows, we have to:

- Abandon (maybe bypass) the core Unix principle of composing programs to carry out more complex tasks - Reimplement a pager library in every language

Is that really the best approach? Even if so, I would have thought a minimal pager would be best, but the feature list of this pager library is fairly extensive: https://github.com/AMythicDev/minus?tab=readme-ov-file#featu...

pie_flavor|4 months ago

    Do One Thing*†‡ And Do It Well⹋
    * Parsing text formats counts as zero things
    † UX counts as two things
    ‡ APIs that do multiple operations that people might want to split, with no individual APIs for the parts, count as doing one thing 
    ⹋ Something that relies on cooperation from every other process on the system but has no way to enforce it counts as done well
Nobody bothers with this argument when the library is for, like, HTTP clients, or PKZIP containers. Unix philosophy, like most philosophy, exists mostly to be debated, and to be related to the history of the world, rather than to be actually implemented in the modern day.

bayindirh|4 months ago

> Do people widely agree with this? That sounds less like 'exploitation' to me and more like 'the way Unix works'.

I personally don't. UNIX is made to be composable, and it's composition. more, less, most all consider pipe input as first-class citizens. I'm personally fond of "grep --color=always file.ext | less --raw" to page colored output.

> Is that really the best approach?

I don't think so. If I was the developer, I'd embed the pager only into the Windows build by default, and use system pagers on other systems (by default). If any person/distro wants to use the built-in pager, it'd be their choice.

I don't like when developers bloat their own code with good intentions, but drift from their nice state to something bloated.

indentit|4 months ago

Having to pipe to a pager - to follow the unix philosophy - means: - extra typing each time - the pager receives static output. There is no interactivity... Sure, most pagers can search. But there is no way to have a table with adjustable columns, or toggle word wrap or line numbers etc.

I feel that for a tool like bat, it is better to have it built-in and not follow the composable philosophy because it is just so much more convenient. Of course the minus integration in bat is fairly basic at the moment, I guess supporting different code paths for static pagers vs interactive would increase maintenance burden quite a lot...

phlakaton|4 months ago

If you think of bat as in the same category of functionality as a pager, I think it works.

Unlike cat, bat already seems deeply interested in the presentation of text on a terminal. Pagination involves several aspects of presentation of text on terminals. So, it's still arguably one thing from a conceptual perspective.

Not knowing much about bat (so I don't know how much this has already been thought of), I could even see bat and pager integrating in a way that you couldn't easily as separate programs. Supporting a feature where the opening lines of a paragraph, or a new section, are deferred to the next page, for example.

rascul|4 months ago

Did Windows stop shipping a pager? 'type file | more' was a thing on MS-DOS and Windows when I used them.

dist-epoch|4 months ago

Most Unix CLI tools don't respect the unix philosophy anyway. For example a lot support something like `--output file.txt` when the Unix philosophy would say to not implement that and just use `>> file.txt`

Narishma|4 months ago

Since when did Windows stop shipping a pager? IIRC it's been there since DOS 2.0 from 1983.

hoistbypetard|4 months ago

When I saw this, I was hoping that [The Bat!](https://www.ritlabs.com/en/products/thebat/) had been released as FOSS. This is still pretty cool.

moepstar|4 months ago

Same, I thought they may have gone through a rebrand or something..

I wonder how long ago it was I last used it - must’ve been sometime around 2010 or a few years earlier..

tecleandor|4 months ago

OMG the flashback... I remember using "The Bat!" and Rimart's "Becky! Internet Mail"

Exclamation marks seemed to be popular in names back in the day :D

aquir|4 months ago

Same here...but this is cool stuff as well!

p0w3n3d|4 months ago

same. I believe I used to have some free version somewhere (bought on a CD with a magazine)

rado|4 months ago

Came here to say exactly that. Loved it back in the day, great app.

sundarurfriend|4 months ago

bat is one of the few "new wave" tools that I install without hesitation, with no worries about stability issues or silent downsides. It has great defaults that make it feel like it always does the right thing for the context, just an unambiguous enhancement to my terminal experience.

bboozzoo|4 months ago

I probably have a bunch of such tools installed on my main machine. The problem is you actually need to remember to use them, and then maybe their command line switches to get the desired output. Whereas cat/less/git/vim are muscle memory. Not to mention that you first need to get over the hum of installing them in your system, likely needing to grab the latest Go/Rust/Zig toolchain along the way.

So while I admire the engineering effort, I still find utility of these tools limited.

jftuga|4 months ago

Agreed. I use this program all day, every day. Viewing a file without it now is just painful. :-)

I have these aliases, which are useful when piping output to them:

    alias bd='bat -p -l diff'
    alias bh='bat -p -l help'
    alias bi='bat -p -l ini'
    alias bj='bat -p -l json'
    alias bl='bat -p -l log'
    alias bm='bat -p -l man'
    alias by='bat -p -l yml'

jampekka|4 months ago

> It has great defaults that make it feel like it always does the right thing for the context

Just tried it out yesterday and it by default output white text on my white background terminal. :(

jesucresta|4 months ago

any other recommendation?

bargainbin|4 months ago

One of the first programs I install in any new setup. Just having the line numbers in your snippets, when all your communication is over asynchronous platforms with UX features designed by the Greatest Minds at Microsoft, streamlines discussions do much.

signa11|4 months ago

oh you cheeky cat ! w3c did a huge disservice by not including the ‘snarky’ tag in their specification.

Moosturm|4 months ago

I love "bat". It just give readability in the terminal a boost.

kI3RO|4 months ago

The builtin pager doesn't have an END shortcut...

it's useless without such a small thing.

edit: [n] G Go to the very bottom of the output. If n is present, goes to that line

Oh capital G. What an intuitive keyword source:https://docs.rs/minus/latest/minus/#standard-actions

ksynwa|4 months ago

It is the same shortcut as less, vim, etc. There is plenty of precedent to choose it.

ctippett|4 months ago

Has anyone had any luck compiling bat for WebAssembly? I tried recently to get a version I could run on a-Shell[1] on iOS, but ran into issues with some of its dependencies.

[1]: https://github.com/holzschu/a-shell

pkilgore|4 months ago

bat is part of my extended posix "Must Installs", nicely extensible, glad to see it get love.

jansan|4 months ago

What is it? It says it is a cat clone, but what is cat?

emil-lp|4 months ago

Bat is a file viewer that supports syntax highlighting and reads git status to also annotate added/deleted/changed lines.

The classic file viewer for a terminal is cat (or less).

atoav|4 months ago

A very wide used command line program that prints out the contents of a file on a terminal. Chances are pretty high cat is installed on your system already.

Example: If you're navigating to the folder of a git repository in your terminal and quickly want to see what the readme says without having to open a file manager or going to the website on github/gitlab/codeberg you can run:

  cat README.md
  
Which shows the text stored in that file directly in your terminal window.

bat does essentially the same, only fancier, with syntax highlighting, some formatting and colors.

trentearl|4 months ago

cat is a classic unix program that outputs the contents of one or more files to stdout. It's short for concatenate