Nikratio
Nikratio

Reputation: 2449

How to paginate git output only when necessary

Is there a way to configure git to pipe its output into a paper only when it exceeds the terminal size (or at least a specific number of lines)? I think it's rather annoying that e.g. a 6-line diff is shown in the pager - hiding any previous output, and requiring me to explicitly press "q" to exit.

Upvotes: 12

Views: 2402

Answers (3)

Matthieu Moy
Matthieu Moy

Reputation: 16527

The behavior you describe is the default. Git starts less, and if $LESS is not set, Git sets it to FRX (see man git-config).

If you don't see this behavior, then most likely someone (some distros do this by default) have set $LESS for you. You can either unset it in your shell's config file, or use one of the other answers.

Upvotes: 1

db48x
db48x

Reputation: 3168

You can configure your pager by setting the PAGER variable, and any program which needs a pager will use it. less has an option -F which does exactly this. Adding export PAGER="less -F" to your ~/.bashrc will make this permanent.

Personally I use less -FXRS; see the man page for less for more details.

Upvotes: 1

Jonathan.Brink
Jonathan.Brink

Reputation: 25393

On most systems, less is the default pager that Git uses and you can configure less to behave like you describe with:

git config --global core.pager "less -X -F"

-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.

See this answer for more options with configuring less.

Also, specifically with regards to the diff command you can use:

git --no-pager diff

Upvotes: 23

Related Questions