Bat: Pager option is not working

Created on 6 Jul 2020  路  4Comments  路  Source: sharkdp/bat

What version of bat are you using?

bat 0.15.4

Describe the bug you encountered:

  • The pager behaviour can't be altered via the PAGER environment variable:
    bash $ echo $PAGER less --quit-if-one-screen --tabs=1 $ echo -e "1234567890\n\ttest=1" | bat STDIN 1 1234567890 2 test=1
    Here I'd expect to have only 1 space is used for tab indent, but in reality bat uses 4.
  • The issue is also present during the following scenarios:

    • if I use BAT_PAGER env variable (same as above but using BAT_PAGER instead of PAGER)

    • if I set the pager argument in the config file (see below)

    • if I set the pager argument directly:

      bash echo -e "1234567890\n\ttest=1" | bat --pager="less --quit-if-one-screen --tabs=1"

Describe what you expected to happen?

  • My understanding of the Using a different pager section of the Readme is the PAGER env variable is used for pager command of bat.
  • The generated config file also implies that arguments can be passed.
    (Although I believe there is also a mistake here: as of src/bin/bat/config.rs:66 I read it as the value should be only arguments, but in reality it expects to prefix it with the less command.)
  • Calling less directly after echo produces correct amount of spaces:
    bash $ echo $LESS # instead of $PAGER --quit-if-one-screen --tabs=1 $ echo -e "1234567890\n\ttest=1" | less 1234567890 alma=1

How did you install bat?

cargo install --git https://github.com/sharkdp/bat.git --tag v0.15.4

system

$ uname -srm
Linux 4.15.0-101-generic x86_64

$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 18.04.4 LTS
Release: 18.04
Codename: bionic

bat

$ bat --version
bat 0.15.4

$ env
PAGER=less --quit-if-one-screen --tabs=1
BAT_CONFIG_PATH=/home/pcdevil/.batrc

bat_config

$ cat /home/pcdevil/.batrc

--theme="Dracula"
--style="numbers,changes,header"
--paging=always
--pager="less --quit-if-one-screen --tabs=1"

bat_wrapper

No wrapper script for 'bat'.

bat_wrapper_function

No wrapper function for 'bat'.

No wrapper function for 'cat'.

tool

$ less --version
less 551 (POSIX regular expressions)

bug

Most helpful comment

Bat itself actually expands the tabs, which is why less --tabs=1 isn't working for you. That was done because of tabstop alignment issues when the sidebar is visible, but you can disable it by adding --tabs=0 to your bat config file. Or, if you just want to change the width of the tabs, you can use --tabs=1 to set it to a single space character

All 4 comments

Bat itself actually expands the tabs, which is why less --tabs=1 isn't working for you. That was done because of tabstop alignment issues when the sidebar is visible, but you can disable it by adding --tabs=0 to your bat config file. Or, if you just want to change the width of the tabs, you can use --tabs=1 to set it to a single space character

Hey,

Thank you for the response, you are right, letting less do the indenting makes an issue due to the line numbering!

Mind if I create a PR for mentioning this in the Readme, alongside the modification of src/bin/bat/config.rs:66 to reflect how bat works?

By all means. Contributions are always welcome!

Thanks, created the merge request for it: #1103

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mjlbach picture mjlbach  路  3Comments

yum-feng picture yum-feng  路  3Comments

antoinemadec picture antoinemadec  路  3Comments

lilyball picture lilyball  路  3Comments

gAmUssA picture gAmUssA  路  3Comments