# [RFC] Clean way to disable pager

15 messages from 2007-08-19 to 2007-08-21. Participants: Matthieu Moy, Linus Torvalds, Brian Gernhardt, Junio C Hamano, Alex Riesen, Adam Roben, David Kastrup, Jakub Narebski, Johannes Schindelin.
Thread: https://gitlist.dev/t/9574

## Matthieu Moy, 2007-08-19 17:26

Subject: [RFC] Clean way to disable pager
Message-ID: <vpq1wdz307k.fsf@bauges.imag.fr>
URL: https://gitlist.dev/e/vpq1wdz307k.fsf%40bauges.imag.fr

```
Hi,

The man page for git documents the -p option to _enable_ the paginated
output for git, which isn't very usefull since the commands that might
actually need paging have it enabled by default.

What I can't find is a clean way to _disable_ the pager. A hacky way
is to run "git whatever | cat", or "GIT_PAGER=cat git whatever". From
the code, it seems that git doesn't even launch the pager if it's set
to "cat".

I think that deserves an less-hacky, and documented way. I'd suggest a
--no-pager, or --dont-paginate, that would do the opposite of -p as a
global option for git.

Below is a patch that does this:




>From 2148c2564ca6480feaec9a9d091259032257918d Mon Sep 17 00:00:00 2001
From: Matthieu Moy <Matthieu.Moy@imag.fr>
Date: Sun, 19 Aug 2007 19:24:36 +0200
Subject: [PATCH] Add and document a global --no-pager option for git.

To keep the change small, this is done by setting GIT_PAGER to "cat". I'd
prefer not using global/environment variables for that, but it would
require a complete refactoring of options handling in git.
---
 Documentation/git.txt |    6 +++++-
 git.c                 |    6 +++++-
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/Documentation/git.txt b/Documentation/git.txt
index 8017997..707a756 100644
--- a/Documentation/git.txt
+++ b/Documentation/git.txt
@@ -9,7 +9,8 @@ git - the stupid content tracker
 SYNOPSIS
 --------
 [verse]
-'git' [--version] [--exec-path[=GIT_EXEC_PATH]] [-p|--paginate]
+'git' [--version] [--exec-path[=GIT_EXEC_PATH]] 
+    [-p|--paginate] [--no-pager]
     [--bare] [--git-dir=GIT_DIR] [--work-tree=GIT_WORK_TREE]
     [--help] COMMAND [ARGS]
 
@@ -103,6 +104,9 @@ OPTIONS
 -p|--paginate::
        Pipe all output into 'less' (or if set, $PAGER).
 
+--no-pager::
+       Do not pipe git output into a pager.
+
 --git-dir=<path>::
        Set the path to the repository. This can also be controlled by
        setting the GIT_DIR environment variable.
diff --git a/git.c b/git.c
index cab0e72..f280e7d 100644
--- a/git.c
+++ b/git.c
@@ -4,7 +4,7 @@
 #include "quote.h"
 
 const char git_usage_string[] =
-       "git [--version] [--exec-path[=GIT_EXEC_PATH]] [-p|--paginate] [--bare] [--git-dir=GIT_DIR] [--work-tree=GIT_WORK_TREE] [--help] COMMAND [ARGS]";
+       "git [--version] [--exec-path[=GIT_EXEC_PATH]] [-p|--paginate] [--no-pager] [--bare] [--git-dir=GIT_DIR] [--work-tree=GIT_WORK_TREE] [--help] COMMAND
 [ARGS]";                                                                                                                                                   
 
 static void prepend_to_path(const char *dir, int len)
 {
@@ -58,6 +58,10 @@ static int handle_options(const char*** argv, int* argc, int* envchanged)
                        }
                } else if (!strcmp(cmd, "-p") || !strcmp(cmd, "--paginate")) {
                        setup_pager();
+               } else if (!strcmp(cmd, "--no-pager")) {
+                       setenv("GIT_PAGER", "cat", 1);
+                       if (envchanged)
+                               *envchanged = 1;
                } else if (!strcmp(cmd, "--git-dir")) {
                        if (*argc < 2) {
                                fprintf(stderr, "No directory given for --git-dir.\n" );
-- 
1.5.3.rc0.64.gf4f4a-dirty



-- 
Matthieu

```

## Matthieu Moy, 2007-08-19 17:41

Subject: Re: [RFC] Clean way to disable pager
Message-ID: <vpqwsvr1kxz.fsf@bauges.imag.fr>
URL: https://gitlist.dev/e/vpqwsvr1kxz.fsf%40bauges.imag.fr
In-Reply-To: <vpq1wdz307k.fsf@bauges.imag.fr>

```
Matthieu Moy <Matthieu.Moy@imag.fr> writes:

> What I can't find is a clean way to _disable_ the pager. A hacky way
> is to run "git whatever | cat", or "GIT_PAGER=cat git whatever". 

I juste realized that the second way is actually documented:


'GIT_PAGER'::
	This environment variable overrides `$PAGER`. If it is set
	to an empty string or to the value "cat", git will not launch
	a pager.

Still, I find this a bit too hidden in the documentation. I'd expect
to find the way to disable the pager close to the place where I find
the way to enable it. Perhaps something like this would do:

--- a/Documentation/git.txt
+++ b/Documentation/git.txt
@@ -101,7 +101,8 @@ OPTIONS
 	the current setting and then exit.
 
 -p|--paginate::
-	Pipe all output into 'less' (or if set, $PAGER).
+	Pipe all output into 'less' (or if set, $GIT_PAGER or $PAGER).
+	See the documentation of GIT_PAGER below to disable the pager.
 
 --git-dir=<path>::
 	Set the path to the repository. This can also be controlled by


Or perhaps move the sentence about "cat" from the documentation of
GIT_PAGER to the one of --paginate (neither place is really
appropriate, it's not specific to GIT_PAGER since setting $PAGER works
also, and not specific to --paginate since many commands enable it
automatically).

-- 
Matthieu

```

## Linus Torvalds, 2007-08-19 17:52

Subject: Re: [RFC] Clean way to disable pager
Message-ID: <alpine.LFD.0.999.0708191051390.30176@woody.linux-foundation.org>
URL: https://gitlist.dev/e/alpine.LFD.0.999.0708191051390.30176%40woody.linux-foundation.org
In-Reply-To: <vpq1wdz307k.fsf@bauges.imag.fr>

```


On Sun, 19 Aug 2007, Matthieu Moy wrote:
> 
> I think that deserves an less-hacky, and documented way. I'd suggest a
> --no-pager, or --dont-paginate, that would do the opposite of -p as a
> global option for git.

Ack. I think it makes sense. The GIT_PAGER thing is equivalent, but at the 
same time, having a way to explicitly disable it with a command line 
option just seems to be the RightThing(tm) to do.

		Linus

```

## Brian Gernhardt, 2007-08-19 18:24

Subject: Re: [RFC] Clean way to disable pager
Message-ID: <819D2F58-960A-4DA4-8FAC-7DE69A78F971@silverinsanity.com>
URL: https://gitlist.dev/e/819D2F58-960A-4DA4-8FAC-7DE69A78F971%40silverinsanity.com
In-Reply-To: <vpq1wdz307k.fsf@bauges.imag.fr>

```

On Aug 19, 2007, at 1:26 PM, Matthieu Moy wrote:

> I think that deserves an less-hacky, and documented way. I'd suggest a
> --no-pager, or --dont-paginate, that would do the opposite of -p as a
> global option for git.

ACK.  I was going to write this pretty soon myself.

~~ Brian

```

## Junio C Hamano, 2007-08-19 18:52

Subject: Re: [RFC] Clean way to disable pager
Message-ID: <7vodh3bbmx.fsf@gitster.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vodh3bbmx.fsf%40gitster.siamese.dyndns.org
In-Reply-To: <vpq1wdz307k.fsf@bauges.imag.fr>

```
Matthieu Moy <Matthieu.Moy@imag.fr> writes:

> I think that deserves an less-hacky, and documented way. I'd suggest a
> --no-pager, or --dont-paginate, that would do the opposite of -p as a
> global option for git.

I think that is a good thing to do.

> From 2148c2564ca6480feaec9a9d091259032257918d Mon Sep 17 00:00:00 2001
> From: Matthieu Moy <Matthieu.Moy@imag.fr>
> Date: Sun, 19 Aug 2007 19:24:36 +0200
> Subject: [PATCH] Add and document a global --no-pager option for git.
>
> To keep the change small, this is done by setting GIT_PAGER to "cat". I'd
> prefer not using global/environment variables for that, but it would
> require a complete refactoring of options handling in git.

And I do not necessarily think this GIT_PAGER thing is a bad way
to do so either.  It may end up spawning other commands (perhaps
via alias) and the use of environment is probably the way with
the least impact and complexity.

Please resend an applyable patch with a sign-off (and acked-by
as you have seen).

```

## Matthieu Moy, 2007-08-19 19:44

Subject: Re: [RFC] Clean way to disable pager
Message-ID: <vpq643bz4vx.fsf@bauges.imag.fr>
URL: https://gitlist.dev/e/vpq643bz4vx.fsf%40bauges.imag.fr
In-Reply-To: <7vodh3bbmx.fsf@gitster.siamese.dyndns.org>

```
Junio C Hamano <gitster@pobox.com> writes:

> Please resend an applyable patch with a sign-off (and acked-by
> as you have seen).

>From 2c79b9a1b446ca9fa9d72fc595120da34fd403dd Mon Sep 17 00:00:00 2001
From: Matthieu Moy <Matthieu.Moy@imag.fr>
Date: Sun, 19 Aug 2007 19:24:36 +0200
Subject: [PATCH] Add and document a global --no-pager option for git.

To keep the change small, this is done by setting GIT_PAGER to "cat".

Acked-by: Linus Torvalds <torvalds@linux-foundation.org>
Acked-by: Brian Gernhardt <benji@silverinsanity.com>
Signed-off-by: Matthieu Moy <Matthieu.Moy@imag.fr>
---
 Documentation/git.txt |    6 +++++-
 git.c                 |    6 +++++-
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/Documentation/git.txt b/Documentation/git.txt
index 8017997..707a756 100644
--- a/Documentation/git.txt
+++ b/Documentation/git.txt
@@ -9,7 +9,8 @@ git - the stupid content tracker
 SYNOPSIS
 --------
 [verse]
-'git' [--version] [--exec-path[=GIT_EXEC_PATH]] [-p|--paginate]
+'git' [--version] [--exec-path[=GIT_EXEC_PATH]] 
+    [-p|--paginate] [--no-pager]
     [--bare] [--git-dir=GIT_DIR] [--work-tree=GIT_WORK_TREE]
     [--help] COMMAND [ARGS]
 
@@ -103,6 +104,9 @@ OPTIONS
 -p|--paginate::
        Pipe all output into 'less' (or if set, $PAGER).
 
+--no-pager::
+       Do not pipe git output into a pager.
+
 --git-dir=<path>::
        Set the path to the repository. This can also be controlled by
        setting the GIT_DIR environment variable.
diff --git a/git.c b/git.c
index cab0e72..f280e7d 100644
--- a/git.c
+++ b/git.c
@@ -4,7 +4,7 @@
 #include "quote.h"
 
 const char git_usage_string[] =
-       "git [--version] [--exec-path[=GIT_EXEC_PATH]] [-p|--paginate] [--bare] [--git-dir=GIT_DIR] [--work-tree=GIT_WORK_TREE] [--help] COMMAND [ARGS]";
+       "git [--version] [--exec-path[=GIT_EXEC_PATH]] [-p|--paginate] [--no-pager] [--bare] [--git-dir=GIT_DIR] [--work-tree=GIT_WORK_TREE] [--help] COMMAND 
[ARGS]";                                                                                                                                                     
 
 static void prepend_to_path(const char *dir, int len)
 {
@@ -58,6 +58,10 @@ static int handle_options(const char*** argv, int* argc, int* envchanged)
                        }
                } else if (!strcmp(cmd, "-p") || !strcmp(cmd, "--paginate")) {
                        setup_pager();
+               } else if (!strcmp(cmd, "--no-pager")) {
+                       setenv("GIT_PAGER", "cat", 1);
+                       if (envchanged)
+                               *envchanged = 1;
                } else if (!strcmp(cmd, "--git-dir")) {
                        if (*argc < 2) {
                                fprintf(stderr, "No directory given for --git-dir.\n" );
-- 
1.5.3.rc0.64.gf4f4a-dirty



-- 
Matthieu

```

## Alex Riesen, 2007-08-19 21:28

Subject: Re: [RFC] Clean way to disable pager
Message-ID: <20070819212827.GA5442@steel.home>
URL: https://gitlist.dev/e/20070819212827.GA5442%40steel.home
In-Reply-To: <vpq1wdz307k.fsf@bauges.imag.fr>

```
Matthieu Moy, Sun, Aug 19, 2007 19:26:07 +0200:
> I think that deserves an less-hacky, and documented way. I'd suggest a
> --no-pager, or --dont-paginate, that would do the opposite of -p as a
> global option for git.

Ack.

Besides, some platforms having no way to unset an environment
variable, a really cumbersome to work with them (Cygwin/Win32, yes),
so this switch is actually the only way to achive something stable.

```

## Adam Roben, 2007-08-19 21:59

Subject: Re: [RFC] Clean way to disable pager
Message-ID: <325563A3-050A-4830-9ACB-9ED15322F038@apple.com>
URL: https://gitlist.dev/e/325563A3-050A-4830-9ACB-9ED15322F038%40apple.com
In-Reply-To: <vpq643bz4vx.fsf@bauges.imag.fr>

```

On Aug 19, 2007, at 12:44 PM, Matthieu Moy wrote:

> +    [-p|--paginate] [--no-pager]

   I think that [-p|--[no-]paginate] would be more consistent with the  
way negatable options are normally specified.

-Adam

```

## David Kastrup, 2007-08-19 22:37

Subject: Re: [RFC] Clean way to disable pager
Message-ID: <85ps1jp2w9.fsf@lola.goethe.zz>
URL: https://gitlist.dev/e/85ps1jp2w9.fsf%40lola.goethe.zz
In-Reply-To: <325563A3-050A-4830-9ACB-9ED15322F038@apple.com>

```
Adam Roben <aroben@apple.com> writes:

> On Aug 19, 2007, at 12:44 PM, Matthieu Moy wrote:
>
>> +    [-p|--paginate] [--no-pager]
>
>   I think that [-p|--[no-]paginate] would be more consistent with the
> way negatable options are normally specified.

Disregard previously existing code, I'd vote for using an option set
like the following:

--pager
--pager=less
--pager=cat
--no-pager

"--paginate" is rather artificial in contrast.

-- 
David Kastrup, Kriemhildstr. 15, 44793 Bochum

```

## Matthieu Moy, 2007-08-20 08:15

Subject: Re: [RFC] Clean way to disable pager
Message-ID: <vpqzm0mvcz0.fsf@bauges.imag.fr>
URL: https://gitlist.dev/e/vpqzm0mvcz0.fsf%40bauges.imag.fr
In-Reply-To: <85ps1jp2w9.fsf@lola.goethe.zz>

```
David Kastrup <dak@gnu.org> writes:

> Adam Roben <aroben@apple.com> writes:
>
>> On Aug 19, 2007, at 12:44 PM, Matthieu Moy wrote:
>>
>>> +    [-p|--paginate] [--no-pager]
>>
>>   I think that [-p|--[no-]paginate] would be more consistent with the
>> way negatable options are normally specified.
>
> Disregard previously existing code, I'd vote for using an option set
> like the following:
>
> --pager
> --pager=less
> --pager=cat
> --no-pager
>
> "--paginate" is rather artificial in contrast.

ACK. I thought of naming the option --no-paginate, but I don't think
that good english. --dont-paginate would be good english, but doesn't
match the --[no-]whatever scheme.

Perhaps using David's proposal, and keeping the --paginate as a
backward compatibility, deprecated switch is the way to go.

-- 
Matthieu

```

## Jakub Narebski, 2007-08-21 02:11

Subject: Re: [RFC] Clean way to disable pager
Message-ID: <fadhkv$amj$2@sea.gmane.org>
URL: https://gitlist.dev/e/fadhkv%24amj%242%40sea.gmane.org
In-Reply-To: <vpqzm0mvcz0.fsf@bauges.imag.fr>

```
Matthieu Moy wrote:
> David Kastrup <dak@gnu.org> writes:
>> Adam Roben <aroben@apple.com> writes:
>>> On Aug 19, 2007, at 12:44 PM, Matthieu Moy wrote:
>>>
>>>> +    [-p|--paginate] [--no-pager]
>>>
>>>   I think that [-p|--[no-]paginate] would be more consistent with the
>>> way negatable options are normally specified.
>>
>> Disregard previously existing code, I'd vote for using an option set
>> like the following:
>>
>> --pager
>> --pager=less
>> --pager=cat
>> --no-pager
>>
>> "--paginate" is rather artificial in contrast.
> 
> ACK. I thought of naming the option --no-paginate, but I don't think
> that good english. --dont-paginate would be good english, but doesn't
> match the --[no-]whatever scheme.
> 
> Perhaps using David's proposal, and keeping the --paginate as a
> backward compatibility, deprecated switch is the way to go.

I like it too. ACK.

-- 
Jakub Narebski
Warsaw, Poland
ShadeHawk on #git

```

## Matthieu Moy, 2007-08-21 08:37

Subject: [PATCH] Replace git --paginate by git --pager[=PAGER_CMD].
Message-ID: <11876854283229-git-send-email-Matthieu.Moy@imag.fr>
URL: https://gitlist.dev/e/11876854283229-git-send-email-Matthieu.Moy%40imag.fr
In-Reply-To: <fadhkv$amj$2@sea.gmane.org>

```
The previous one was -p|--paginate, but doesn't accept a natural
negation. This patch changes it to -p|--pager|--pager=PAGER_CMD, which
makes the negation --no-pager more natural, and provides a simple way to
override the pager command (git --pager=CMD is equivalent to
GIT_PAGER=CMD git with most shells).

--paginate is kept as a backward-compatibility, deprecated option.

Suggested-by: David Kastrup <dak@gnu.org>
Idea-acked-by: Jakub Narebski <jnareb@gmail.com>

Signed-off-by: Matthieu Moy <Matthieu.Moy@imag.fr>
---
 Documentation/git.txt |    8 +++++---
 git.c                 |   16 ++++++++++++++--
 2 files changed, 19 insertions(+), 5 deletions(-)

diff --git a/Documentation/git.txt b/Documentation/git.txt
index 3b0d530..444823d 100644
--- a/Documentation/git.txt
+++ b/Documentation/git.txt
@@ -10,7 +10,7 @@ SYNOPSIS
 --------
 [verse]
 'git' [--version] [--exec-path[=GIT_EXEC_PATH]]
-    [-p|--paginate|--no-pager]
+    [-p|--pager[=PAGER_CMD]|--no-pager]
     [--bare] [--git-dir=GIT_DIR] [--work-tree=GIT_WORK_TREE]
     [--help] COMMAND [ARGS]
 
@@ -101,8 +101,10 @@ OPTIONS
 	environment variable. If no path is given 'git' will print
 	the current setting and then exit.
 
--p|--paginate::
-	Pipe all output into 'less' (or if set, $PAGER).
+-p|--pager[=PAGER_CMD]::
+	Pipe all output into 'less' (or if set, PAGER_CMD,
+	`$GIT_PAGER`, or `$PAGER`, in this order of preference).
+	--paginate is provided as a deprecated alias for -p.
 
 --no-pager::
 	Do not pipe git output into a pager.
diff --git a/git.c b/git.c
index c46691e..4c626b5 100644
--- a/git.c
+++ b/git.c
@@ -4,7 +4,9 @@
 #include "quote.h"
 
 const char git_usage_string[] =
-	"git [--version] [--exec-path[=GIT_EXEC_PATH]] [-p|--paginate|--no-pager] [--bare] [--git-dir=GIT_DIR] [--work-tree=GIT_WORK_TREE] [--help] COMMAND [ARGS]";
+	"git [--version] [--exec-path[=GIT_EXEC_PATH]]\n"
+        "	[-p|--pager[=PAGER_CMD]|--no-pager] [--bare]\n"
+        "	[--git-dir=GIT_DIR] [--work-tree=GIT_WORK_TREE] [--help] COMMAND [ARGS]";
 
 static void prepend_to_path(const char *dir, int len)
 {
@@ -56,8 +58,18 @@ static int handle_options(const char*** argv, int* argc, int* envchanged)
 				puts(git_exec_path());
 				exit(0);
 			}
-		} else if (!strcmp(cmd, "-p") || !strcmp(cmd, "--paginate")) {
+		} else if (!strcmp(cmd, "-p") || 
+                           /* 
+                            * Deprecated, but kept for backward
+                            * compatibility
+                            */
+                           !strcmp(cmd, "--paginate")) {
 			setup_pager();
+                } else if (!prefixcmp(cmd, "--pager")) {
+			cmd += 7;
+			if (*cmd == '=')
+				setenv("GIT_PAGER", cmd+1, 1);
+                        setup_pager();
 		} else if (!strcmp(cmd, "--no-pager")) {
 			setenv("GIT_PAGER", "cat", 1);
 			if (envchanged)
-- 
1.5.3.rc5.17.g1cd0d-dirty

```

## Johannes Schindelin, 2007-08-21 08:42

Subject: Re: [PATCH] Replace git --paginate by git --pager[=PAGER_CMD].
Message-ID: <Pine.LNX.4.64.0708211041170.16728@wbgn129.biozentrum.uni-wuerzburg.de>
URL: https://gitlist.dev/e/Pine.LNX.4.64.0708211041170.16728%40wbgn129.biozentrum.uni-wuerzburg.de
In-Reply-To: <11876854283229-git-send-email-Matthieu.Moy@imag.fr>

```
Hi,

On Tue, 21 Aug 2007, Matthieu Moy wrote:

> The previous one was -p|--paginate, but doesn't accept a natural
> negation. This patch changes it to -p|--pager|--pager=PAGER_CMD, which
> makes the negation --no-pager more natural, and provides a simple way to
> override the pager command (git --pager=CMD is equivalent to
> GIT_PAGER=CMD git with most shells).
> 
> --paginate is kept as a backward-compatibility, deprecated option.

Personally, I like to read "git --paginate log" better than to read "git 
--pager log".  So I would not unnecessarily deprecate --paginate.  It's 
not like it hurts or something.

Ciao,
Dscho

```

## Matthieu Moy, 2007-08-21 08:51

Subject: Re: [PATCH] Replace git --paginate by git --pager[=PAGER_CMD].
Message-ID: <vpqtzqte0dp.fsf@bauges.imag.fr>
URL: https://gitlist.dev/e/vpqtzqte0dp.fsf%40bauges.imag.fr
In-Reply-To: <Pine.LNX.4.64.0708211041170.16728@wbgn129.biozentrum.uni-wuerzburg.de>

```
Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:

> Personally, I like to read "git --paginate log" better than to read "git 
> --pager log".  So I would not unnecessarily deprecate --paginate.  It's 
> not like it hurts or something.

It doesn't "hurt", but having several options to do the same thing is
useless and confusing (someone reading here about --paginate and there
about --pager may not immediately notice that one is an alias for the
other).

Anyway, how often do you type or read "git --paginate log"?

-- 
Matthieu

```

## David Kastrup, 2007-08-21 09:19

Subject: Re: [PATCH] Replace git --paginate by git --pager[=PAGER_CMD].
Message-ID: <868x85gs8b.fsf@lola.quinscape.zz>
URL: https://gitlist.dev/e/868x85gs8b.fsf%40lola.quinscape.zz
In-Reply-To: <vpqtzqte0dp.fsf@bauges.imag.fr>

```
Matthieu Moy <Matthieu.Moy@imag.fr> writes:

> Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:
>
>> Personally, I like to read "git --paginate log" better than to read "git 
>> --pager log".  So I would not unnecessarily deprecate --paginate.  It's 
>> not like it hurts or something.
>
> It doesn't "hurt", but having several options to do the same thing is
> useless and confusing (someone reading here about --paginate and there
> about --pager may not immediately notice that one is an alias for the
> other).
>
> Anyway, how often do you type or read "git --paginate log"?

Since it is the default anyway...

Maybe one should have a way to tell git "don't use a pager by default,
but _if_ someone says --pager, _then_ use the following pager".

If one has to set the pager to "cat" to disable paging, using --pager
will not exactly be impressive.

So maybe --no-pager/--pager (or an equivalent config file setting)
should not tamper with the setting of GIT_PAGER, but rather set/reset
an independent flag.

-- 
David Kastrup

```
