1. 30
  1.  

  2. 10

    This might be a stupid question, but why not less instead of cat? Cat is not really meant to display files but to concatenate them. I’d definitely like a better pager, but neither w3m or vi in view mode worked for me, so i’m still using less

    1. 5

      Cat is still cat. Bat is like the kitchen sink that just clobbers more? Yeah, I don’t quite understand why this tool is positioning itself relative to cat.

      It is definitely not a clone. But I am all for new, more usable terminal based tools that use what we have at our disposal, more cores, more ram, ssd read/write.

      I’d really like a tool that built an n-gram inverted index of all files below my current dir and allowed me to jump to anything, that showed similar token/phrases/lines, etc. All terminal driven, with an option to load a rich GUI over a local http connection.

      1. 3

        Although I agree with you, I can see why this would be positioned as an alternative to cat.

        Quite a lot of people use cat to preview files, and that’s what bat does. I know less and more exist, but for some reason I still find myself using cat. Perhaps other people do the same.

        1. 4

          I use cat because, if I’m lucky, the output will fit in my terminal, and I’m ready for my next command; with a pager, I need to press a key to exit out of the pager before I can issue my next command, and the output disappears (in the case of less) as if the pager never ran, so I can’t keep context around.

          1. 11

            By the way, less can be configured to act well in these circumstances. I have more as an alias for less -FX. Those two options to less are:

                   -F or --quit-if-one-screen
                          Causes less to automatically exit if the entire file can be displayed on the first screen.
                   -X or --no-init
                          Disables sending the termcap initialization and deinitialization strings to the terminal.  This is sometimes desirable if the deinitialization string does something unnecessary, like clearing the screen.
            

            I also define $PAGER to be less -FX, so manpages and the like don’t clear the screen once the pager quits.

            1. 5

              I second this. -c would be helpful in $PAGER as well so that everything above on your screen stays untouched.

              Personally, I’ve been rolling with this:

              $ type le
              le is an alias for 'less -FcmNqX --follow-name'
              
            2. 2

              the output disappears (in the case of less) as if the pager never ran, so I can’t keep context around.

              If you want to get rid of this sort of behaviour globally, disable “alternate screen” in your terminal.

              In tmux, set-window-option -g alternate-screen off. In putty there’s Disable switching to alternate terminal screen under Terminal → Features.

              1. 1

                Just tested bat, and the output doesn’t disappear. When you need a specific section from a file (not the whole thing) - using bat over cat and not less makes sense. Neat.

            3. 2

              Bat will act like cat if it determines there is no tty. Thus, bat is like less when used interactive and like cat when scripting.

              Like someone else said, people use cat to dump contents to the terminal so they can refer to it while continuing work.

              1. 2

                Proof!

                Oh.. you can also use it to concatenate files 😉. Whenever bat detects a non-interactive terminal, it will fall back to printing the plain file contents.

            4. 2

              I tried it and it did not take long before I ran pkg remove bat.

              It tries to do too much. First of all, the colour scheme assumes a dark background. I couldn’t even read various parts of the files I looked at because of the colours. I can adjust the themes, sure, but I had to start testing out themes just to view files.

              There was also an excessive amount of file decoration. File titles, lines akin to a spreadsheet, line numbers, and so forth. Copying chunks of text in a terminal window just got more tedious.

              Even worse, it used less to page things, so when I tried toggling options for less after running bat quicklisp.lisp (for example, typing -N to display line numbers), I got two columns of line numbers (see image).

              Hard pass on this tool.

              1. 2

                A heavier version of cat? Perhaps fat would’ve been a more apt name.

                1. 2

                  You get an upvote, but only because you made me laugh!

                2. 1

                  To be fair, cat also supports line numbering:

                  $ cat -n helloworld.txt 
                     1 hello
                     2 unix
                     3 world
                  

                  so if you need only numbering, you can stick with cat.