Bat v0.26.0

129 pointsposted 11 hours ago
by indentit

61 Comments

oneeyedpigeon

8 hours 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

5 hours 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

8 hours 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.

pie_flavor

5 hours ago

Bloat cannot mean large contributor to the code size, since it's a tiny portion of the binary and dwarfed by the regex, syntax highlighter, and (sigh) command-line parsing. It also cannot mean unwanted feature, since every single time I have ever used it to look at a file I have wanted it paged, and I can't think of a circumstance where I wouldn't want it paged (given that my terminal is already set up to work with pagers, and otherwise I'd be well acquainted with configuring things not to be paged). So I wonder what it could mean in this context. (Myself I am fond of not wasting the same twenty seconds over and over again typing bonus things.)

bayindirh

5 hours ago

Bloat is generally code complexity, which slows down maintenance and development.

In this case, there's a new pager library, conditional connections to the pager library, and possibly the whole shebang of supporting both internal and external pagers at the same time.

I seldom use bat, and I'm not hating it. Syntax highlighting and line numbering looks nice for the use cases I played with it, but I don't find chaining a couple of pipes together to get something exactly I want, a waste of time, esp. when mangling outputs of commands and taking actions according to these outputs.

Development and system administration calls for different conventions on the terminal, and I understand & respect how developers like to "enhance" their terminals to work faster. OTOH, after having both hats for a very long time, I find most (if not all) of these "enhancements" unnecessary because it's either distracting or getting in the way.

For the most tiring and most-used expressions, I use espanso to expand them on the terminal instantly, and I found that doing this gives me more flexibility without it being on my face.

Maybe this is because I can think further steps while typing something in, and I don't waste that time in a sense many people sees. Maybe we shouldn't strive to extract efficiency over every nanosecond of work, and maybe there's something happening we don't quite grasp in these moments we label as "waste".

IDK.;)

phlakaton

4 hours 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.

indentit

7 hours 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...

temp20251020

5 hours ago

The `less` command can toggle line numbers (`-N`, either as a command line argument, or while running it interactively) and toggle line wrapping (`-S`, again either way). It can also receive streamed output with `+F`, making it a viable alternative to `tail -f`. (I'm not sure if what you meant by static output is that it all has to be available before the command can read it.)

It can't adjust the columns in a table, but then I don't believe that `bat` can either, and I'm not aware of any similar program that can. (If there is one, please let me know.)

In the case of `bat` (or `man` or other programs that use a pager) it often requires no extra typing either, since `bat` will pipe it's output to `less` by default (or whatever you specify with the `PAGER` environment variable).

The `less` command can be quite a bit more powerful than it initially looks. I'd recommend looking over the man page sometime -- you might be surprised. In fact, looking over the `minus` page, other than being able to be compiled into another program so it doesn't have to be shipped separately on Windows, I'm not sure what it can do that `less` cannot. (If I'm missing some killer feature, please let me know. I'm not trying to bash `minus`, I just don't know what more it offers.)

rascul

5 hours ago

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

dist-epoch

7 hours 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`

weinzierl

7 hours ago

I think practical Unix philosophy is more nuanced. There are filter programs that read STDIN and write to STDOUT per default.

But this is not really practical for many use cases which are not filters first and foremost. So we end up with still reading from STDIN or the list of files presented as arguments. We write to the file given by -o (or --output) which can be "-" to signify STDOUT.

I find this pattern very flexible because it allows multiple input files or STDIN and a single output file which can be STOUT, so you still get your filtering behaviour if you want.

(For completeness sake, there is a third pattern somewhat prevalent. In call these copy type programs. They treat the last argument specially, usually as some form of target, like `cp a b c target`.)

dist-epoch

7 hours ago

--output was just one example. Many tools provide formatting options, ls can sort, find can delete files it finds, and so on.

bayindirh

6 hours ago

I don't believe programs able to sort their output is acting against the UNIX philosophy. "ls" lists files and does a good job of it. find's -exec is a bit stretching it (-delete came later IIRC), but generally it adheres the philosophy pretty well.

From my experience of programming small utilities for myself, UNIX philosophy says "a tool handles a single job and handles it well" is a nod to fallacy of "gluing" things together.

Because when you start to glue things beyond simple pipes, the glue code becomes exponentially complex and takes more and more of the program, which creates a maintenance hell and affects performance (much more profoundly on a PDP).

So, simple tools doing single things is both easier to write and maintain, and they're much more performant in general.

Remember the guy who left a whole Hadoop cluster in the dust with GNU command line tools and some pipes, on a small laptop.

bayindirh

7 hours ago

From my experience, --output is a minority in my workflow. Which tools do you use need --output?

oneeyedpigeon

7 hours ago

Coincidentally, I went looking for some the other day and there were very few. Everything that uses --output for this purpose, that I could find, was a compiler.

onestay42

7 hours ago

dd an company require if= and of=, if that counts

bayindirh

6 hours ago

dd doesn't require either if= or of=. It'll read from stdin (or pipe) if you omit if= and it'll write to stdout happily if you omit of=.

From the man page:

    if=FILE - read from FILE instead of stdin.
    of=FILE -  write to FILE instead of stdout.
So you can do:

   cat x.iso | dd oflag=direct bs=4096kB | /dev/sdc

hoistbypetard

10 hours 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

10 hours 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

8 hours 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

pilif

5 hours ago

Becky was so good for participating in mailing lists. I could slip by as a Unix user even though I was still mostly using Windows as my client OS.

aquir

9 hours ago

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

p0w3n3d

9 hours ago

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

rado

10 hours ago

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

ctippett

44 minutes 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

sundarurfriend

8 hours 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

8 hours 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.

Cyphus

4 hours ago

I’m in the same boat with a lot of these tools, but bat is different in that it’s compatible enough to be safe to alias to the command it's replacing[1]. You can continue to use cat as usual, with the benefit of getting syntax-highlighted output.

[1]: Assuming you use the `--paging=never` flag in your alias as the README suggests.

oneeyedpigeon

8 hours ago

brew usually manages to install these tools for me with no problems. And on the memory point, there's always `alias` or adding a symlink in ~/.local/bin. But, yeah, I have the exact same problem remembering to use `eza`. For some reason, I don't find `bat` as much of a problem; ls is probably more ingrained.

jftuga

2 hours 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'

jesucresta

8 hours ago

any other recommendation?

theshrike79

7 hours ago

Along with bat, these are my main ones that I install always:

fd, a better find: https://github.com/sharkdp/fd

ripgrep (rg) a modern grep: https://github.com/BurntSushi/ripgrep

eza for ls replacement: https://github.com/eza-community/eza

duf is a cleaner df: https://github.com/muesli/duf

dust for du: https://github.com/bootandy/dust

Also fish + starship + yazi + helix, all of which mostly work perfectly with the defaults

ikety

6 hours ago

I stopped using eza and lsd in favor of aliasing nushell's ls command.

I guess it's not worth the entire dependency of nushell if you don't see yourself ever dabbling with it in other ways (you should it's sick).

Also I'd add to your list zoxide

I've aliased cat to bat, cd to zoxide, and ls to nushell ls with zero issues.

jadbox

4 hours ago

Zsh > fish for me. It's about script compatibility.

theshrike79

3 hours ago

All my scripts start with #!/bin/bash

Zero issues with compatibility

fredoliveira

7 hours ago

What is helix? Haven't heard of it before, I don't think.

Melonai

6 hours ago

Helix is a Vim/Kakoune-inspired modal editor, with a bunch of stuff built in by default. For example it has support for a huge amount of LSPs and intergrates them automatically.

It's command structure is also super similar to Vim's, but, basically, "flipped" around. So you wouldn't write "dw" to delete a word, but "wd". This means that you can see whatever you're selecting to be deleted highlighted before you actually execute the deletion. It has a bunch of saner commands also for stuff people usually want to do, like go to definition/usage, and honestly for people who aren't Vim-addicts such as myself, it's probably a good idea to check it out once, to see if it's a good fit for you.

theshrike79

5 hours ago

I tried getting into nvim (handy for editing from the CLI or over ssh), but within weeks the plugin system started getting weird errors.

Then I tested Helix[0] when a friend suggested it and it Just Works. Along with LSP support that just picks up language servers automatically if you install them.

The target-action command style takes some getting used to after (n)vim's action-target style, but I actually prefer it now.

[0] https://helix-editor.com

DiabloD3

4 hours ago

fwiw, the plugin system doesn't magically just get "weird errors", its always some form of user negligence.

theshrike79

3 hours ago

I literally didn’t touch it and it started throwing errors :)

AbuAssar

7 hours ago

super useful list, you probably should expand it into a blog post

bargainbin

8 hours 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

8 hours ago

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

Moosturm

9 hours ago

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

pkilgore

3 hours ago

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

jansan

10 hours ago

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

emil-lp

9 hours 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).

goku12

9 hours ago

Just a nitpick. The real use of cat is to concatenate two or more files and dump the result in its stdout. But people use it more like file viewer these days.

Bat is a file viewer in every sense. I have concatenated multiple files using bat. It does come in handy sometimes. But even the concatenated output is designed to be a visual aid, not the traditional concatenation that cat does.

chiffaa

8 hours ago

To be 100% fair, Bat only acts this way when used in an interactive environment. As far as I know, in non-interactive cases (a la shell scripting) it falls back to normal cat behaviour

goku12

4 hours ago

That's interesting! How did you know?

chiffaa

an hour ago

Their README claims the following

> Whenever bat detects a non-interactive terminal (i.e. when you pipe into another process or into a file), bat will act as a drop-in replacement for cat and fall back to printing the plain file contents

which was good enough for me personally, but I also have seen anecdotal evidence of people running `alias cat=bat` with a bunch of your usual bash piping work without any issues

JohnKemeny

9 hours ago

Just a nitpick. They said the classic file viewer is cat, not that cat's primary purpose was viewing files.

trentearl

10 hours ago

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

cpach

9 hours ago

Nit-pick: It’s short for catenate (:

atoav

10 hours 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.