Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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



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


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.


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


That's interesting! How did you know?


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


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


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.


It doesn't do that actually. It concatenates files. From the description on the man page:

    Concatenate FILE(s) to standard output.

    With no FILE, or when FILE is -, read standard input
https://man7.org/linux/man-pages/man1/cat.1.html


Yeah sure, that is what happens when you feed your cat multiple files.

Cat in 99% of the usage cases is used on one file


No. What is stated by the manual is what cat does. What you said was simply incorrect.

It does have the effect of what you describe if one file is supplied and might be the most common use case. That doesn't make your description correct, at best it makes it incomplete.


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


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




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: