Open Hashino opened 10 months ago
I noticed this behavior only if the BAT_PAGER
environment variable is defined.
$ echo $PAGER
less -Ln
$ echo $BAT_PAGER
less -Ln
# shows file using less
$ bat one-line-file.txt
# cats file to terminal
$ unset BAT_PAGER
$ bat one-line-file.txt
THIS IS A ONE-LINE FILE
However, if I alter the BAT_PAGER
variable so that it includes the -F
option for less
according the bat
README, ("The second option (-F) instructs less to exit immediately if the output size is smaller than the vertical size of the terminal. This is convenient for small files because you do not have to press q to quit the pager.") everything works as expected!
$ export BAT_PAGER='less -RFLn'
# cats file to terminal
$ bat one-line-file.txt
THIS IS A ONE-LINE FILE
If you want to use another pager app, you'll have to see if it supports an option similar to less -F
.
Love the look of your WM.
Regarding the issue, @erhhung is correct. Unless asked not to, bat
will always pipe its output into the pager (which by default, is less
). less
will take up the full terminal and be interactive regardless of the number of lines except when --quit-if-one-screen
is passed to it as a command-line argument.
The code behind it is a bit complicated, but in most cases, bat
will automatically add that argument to less
. Explicitly setting bat
's pager may prevent that from happening in the following cases:
less
.--pager
contains any command-line arguments (e.g. --pager="less --mouse"
)BAT_PAGER
contains any command-line arguments (e.g. export BAT_PAGER="less --mouse"
)BAT_PAGING
environment variable set to always
.--paging=always
provided to bat
.Without knowing more about how bat
is configured in your environment, @Hashino, I can't tell you exactly why bat
isn't giving --quit-if-one-screen
to less
by default. If you want to give us that info, you can paste the output of bat --diagnostics
as a comment on this issue or edit it into the original comment :)
What steps will reproduce the bug?
What happens?
bat
will always use the pager, regardless of file content.https://github.com/sharkdp/bat/assets/5542633/478940e8-dbfa-4dd9-bd6c-67cb608b4629
What did you expect to happen instead?
for the text to be displayed in the terminal without the pager when the file content fitss, like it happens when i use
--paging=never
How did you install
bat
?sudo pacman -Syu bat
bat version and environment