Prevent git from using pager for short output?
As of December 2017 if you are using the latest version of less
(at least 530) then the below is slightly incorrect. Now -F
alone will properly output short output (as if by cat
) while not needing -X
. Since you can now use -F
alone to see short output this means long output will still be properly wiped from the screen once you close less
! I highly recommend you update your version of less
to get this behavior. It's great!
Schwern's answer is half correct. For what I was asking it is probably still the correct answer, I was just using the incorrect words. What I wanted wasn't this:
-F or --quit-if-one-screen Causes less to automatically exit if the entire file can be dis‐ played on the first screen.
That makes nothing appear for short output! If core.pager
is less -F
and your log is less than one screen, you see nothing.
What you probably want is less -FX
or maybe less -X
.
-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 clear‐ ing the screen.
This question over at superuser led me to this.
Using -FX
if the log is less than one screen then it just outputs it (as if by cat
).
Using only -X
will still open less
if the output is less than one screen but will leave it on the terminal if you quit, if you don't quit right away you can actually use less
like normal. Once you try to search though it brings it into "real" less and still does not wipe when done, which is annoying because the windows is now full of ~
's.
Summary
- If you don't care what happens with short output, use
less
- If you have an older version of
less
than 530 and you want short output to be put on the screen as if bycat
useless -XF
- If you have version 530 or newer then just use
less -F
. See the top of the answer for more info.
- If you have version 530 or newer then just use
- If you want to perhaps search short output (even though it's less than one screen) then use
less -X
, but you will have to still press q.
Quick answer: Save the following line to your .bashrc
export LESS=eFRX
The whys and wherefores are covered in the answers to How do I prevent git diff from using a pager? where the OP is actually looking to remove pagination completely.
You could configure git to use cat
as the pager (instead of less
).
git config --global core.pager cat
This will add the section
[core]
pager = cat
to your ~/.gitconfig file and pipe everything through cat
, i.e. just display it.
It's discussed here How do I prevent git diff from using a pager? in more detail.
You can do this to keep LESS for all git output but always return if there is only 1 page, no exports needed.
git config --global core.pager 'less -F'