Bat: Automatic paging

Created on 1 May 2018  路  5Comments  路  Source: sharkdp/bat

First off, this is nice :).

Have you thought about adding git-style automatic paging to it? If the lines fit on one screen, it would not do paging (like the current behavior). But as soon as it's more than one screen, it could automatically page.

That's one of the things that git got right IMO.

feature-request

Most helpful comment

Not quite what we want, but I just learned that less can be configured to use external programs:

$ export LESS="-R"  # argument to allow less to show colors
$ export LESSOPEN="| bat %s"
$ less lib.rs
# pretty colors, plus paging

All 5 comments

Thank you for the feedback!

Automatic paging sounds like a great idea. Does anyone know how this is achieved in Git? Would we somehow pipe our own output into less?

By the way, bat .. | less works fine - even with colors (see also #26).

Not quite what we want, but I just learned that less can be configured to use external programs:

$ export LESS="-R"  # argument to allow less to show colors
$ export LESSOPEN="| bat %s"
$ less lib.rs
# pretty colors, plus paging

Looks like what Git does is this:

The F and X options together are what automatically make less quit if the output fits on one screen. R is so that less uses the color escape sequences.

By the way, bat .. | less works fine - even with colors (see also #26).

I get the raw escape codes instead of coloring for that, unless I set the LESS env variable before. If it works for you then maybe you have LESS set already. Try unsetting it and then running it.

Looks like what Git does is this:

  • set the LESS env variable to FRX, see release notes of Git 2.1.0
  • invokes less as the pager, see git config reference

Thank you for investigating. This seems to be the part where it launches the pager: https://github.com/git/git/blob/f0294f474e16840f4efb3f4da3329ba46f53efa7/pager.c#L119-L134

It should be possible to implement something similar.

I get the raw escape codes instead of coloring for that, unless I set the LESS env variable before. If it works for you then maybe you have LESS set already.

You are right. Didn't realize $LESS was already configured somewhere.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

yannallain picture yannallain  路  3Comments

antoinemadec picture antoinemadec  路  3Comments

issmirnov picture issmirnov  路  3Comments

HakubJozak picture HakubJozak  路  3Comments

tomgoren picture tomgoren  路  3Comments