# [PATCH] pager: config variable pager.program

5 messages from 2006-07-29 to 2006-07-31. Participants: Matthias Lederhofer, Junio C Hamano, Johannes Schindelin.
Thread: https://gitlist.dev/t/5039

## Matthias Lederhofer, 2006-07-29 21:28

Subject: [PATCH] pager: config variable pager.program
Message-ID: <E1G6wM1-00040z-Bu@moooo.ath.cx>
URL: https://gitlist.dev/e/E1G6wM1-00040z-Bu%40moooo.ath.cx

```
Signed-off-by: Matthias Lederhofer <matled@gmx.net>
---
I'd like to use another pager (or other options) with git than the
normal pager.  Normally I would not want the -R option with less but
for git less should show colors.
---
 Documentation/config.txt |    5 +++++
 pager.c                  |   16 +++++++++++++++-
 2 files changed, 20 insertions(+), 1 deletions(-)

diff --git a/Documentation/config.txt b/Documentation/config.txt
index 465eb13..96429b6 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -116,6 +116,11 @@ apply.whitespace::
 	Tells `git-apply` how to handle whitespaces, in the same way
 	as the '--whitespace' option. See gitlink:git-apply[1].
 
+pager.program::
+	Use this program as pager.  git will try this configuration
+	variable first, then the 'PAGER' environment variable and
+	"less" as fallback.
+
 diff.color::
 	When true (or `always`), always use colors in patch.
 	When false (or `never`), never.  When set to `auto`, use
diff --git a/pager.c b/pager.c
index 280f57f..3f753f6 100644
--- a/pager.c
+++ b/pager.c
@@ -5,6 +5,18 @@ #include "cache.h"
  * something different on Windows, for example.
  */
 
+static const char *pager = NULL;
+
+static int git_pager_config(const char *var, const char *value)
+{
+	if (!strcmp(var, "pager.program")) {
+		if (value)
+			pager = strdup(value);
+		return 0;
+	}
+	return 0;
+}
+
 static void run_pager(const char *pager)
 {
 	execlp(pager, pager, NULL);
@@ -15,10 +27,12 @@ void setup_pager(void)
 {
 	pid_t pid;
 	int fd[2];
-	const char *pager = getenv("PAGER");
 
 	if (!isatty(1))
 		return;
+	git_config(git_pager_config);
+	if (!pager)
+		pager = getenv("PAGER");
 	if (!pager)
 		pager = "less";
 	else if (!*pager || !strcmp(pager, "cat"))
-- 
1.4.2.rc2.g688a

```

## Junio C Hamano, 2006-07-31 00:43

Subject: Re: [PATCH] pager: config variable pager.program
Message-ID: <7v8xmabo37.fsf@assigned-by-dhcp.cox.net>
URL: https://gitlist.dev/e/7v8xmabo37.fsf%40assigned-by-dhcp.cox.net
In-Reply-To: <E1G6wM1-00040z-Bu@moooo.ath.cx>

```
I am not enthused about any configuration stored in .git/config
to override the environment variables.  Files are to store
reasonable default, and command line flags and environments are
to override them, but this patch does it the other way around.

```

## Matthias Lederhofer, 2006-07-31 12:14

Subject: [PATCH] pager: config variable pager.program
Message-ID: <E1G7WfC-000728-9j@moooo.ath.cx>
URL: https://gitlist.dev/e/E1G7WfC-000728-9j%40moooo.ath.cx
In-Reply-To: <7v8xmabo37.fsf@assigned-by-dhcp.cox.net>

```
Signed-off-by: Matthias Lederhofer <matled@gmx.net>
---
Junio C Hamano <junkio@cox.net> wrote:
> I am not enthused about any configuration stored in .git/config
> to override the environment variables.  Files are to store
> reasonable default, and command line flags and environments are
> to override them, but this patch does it the other way around.
You're right, this patch uses $GIT_PAGER.  I don't think pager.program
does make much sense with this (expect someone does not want to export
$PAGER/$GIT_PAGER), should it be introduced anyway (I don't need
it)?
---
 Documentation/git.txt |    3 +++
 pager.c               |    5 ++++-
 2 files changed, 7 insertions(+), 1 deletions(-)

diff --git a/Documentation/git.txt b/Documentation/git.txt
index 7310a2b..d243883 100644
--- a/Documentation/git.txt
+++ b/Documentation/git.txt
@@ -627,6 +627,9 @@ git Diffs
 
 other
 ~~~~~
+'GIT_PAGER'::
+	This environment variable overrides `$PAGER`.
+
 'GIT_TRACE'::
 	If this variable is set git will print `trace:` messages on
 	stderr telling about alias expansion, built-in command
diff --git a/pager.c b/pager.c
index 280f57f..ab9be5d 100644
--- a/pager.c
+++ b/pager.c
@@ -15,10 +15,13 @@ void setup_pager(void)
 {
 	pid_t pid;
 	int fd[2];
-	const char *pager = getenv("PAGER");
+	char *pager;
 
 	if (!isatty(1))
 		return;
+	pager = getenv("GIT_PAGER");
+	if (!pager)
+		pager = getenv("PAGER");
 	if (!pager)
 		pager = "less";
 	else if (!*pager || !strcmp(pager, "cat"))
-- 
1.4.2.rc2.g91b7

```

## Johannes Schindelin, 2006-07-31 12:56

Subject: Re: [PATCH] pager: config variable pager.program
Message-ID: <Pine.LNX.4.63.0607311454040.29667@wbgn013.biozentrum.uni-wuerzburg.de>
URL: https://gitlist.dev/e/Pine.LNX.4.63.0607311454040.29667%40wbgn013.biozentrum.uni-wuerzburg.de
In-Reply-To: <E1G7WfC-000728-9j@moooo.ath.cx>

```
Hi,

On Mon, 31 Jul 2006, Matthias Lederhofer wrote:

> Signed-off-by: Matthias Lederhofer <matled@gmx.net>

The commit message no longer reflects what the patch does ;-)

> -	const char *pager = getenv("PAGER");
> +	char *pager;

You do not need to lose the "const" (it means that you cannot access the 
memory it points to, but you can change the pointer). Also, you could make 
a more minimal patch by replacing PAGER by GIT_PAGER here, instead of 
having this extra line:

> +	pager = getenv("GIT_PAGER");

Ciao,
Dscho

```

## Matthias Lederhofer, 2006-07-31 13:27

Subject: [PATCH] pager: environment variable GIT_PAGER to override PAGER
Message-ID: <E1G7XnQ-0002bA-Fm@moooo.ath.cx>
URL: https://gitlist.dev/e/E1G7XnQ-0002bA-Fm%40moooo.ath.cx
In-Reply-To: <Pine.LNX.4.63.0607311454040.29667@wbgn013.biozentrum.uni-wuerzburg.de>

```
Signed-off-by: Matthias Lederhofer <matled@gmx.net>
---
Johannes Schindelin <Johannes.Schindelin@gmx.de> wrote:
> Hi,
> 
> On Mon, 31 Jul 2006, Matthias Lederhofer wrote:
> 
> > Signed-off-by: Matthias Lederhofer <matled@gmx.net>
> 
> The commit message no longer reflects what the patch does ;-)
> 
> > -	const char *pager = getenv("PAGER");
> > +	char *pager;
> 
> You do not need to lose the "const" (it means that you cannot access the 
> memory it points to, but you can change the pointer). Also, you could make 
> a more minimal patch by replacing PAGER by GIT_PAGER here, instead of 
> having this extra line:
> 
> > +	pager = getenv("GIT_PAGER");
Thanks, I should be more careful when correcting a patch with
--amend.
---
 Documentation/git.txt |    3 +++
 pager.c               |    4 +++-
 2 files changed, 6 insertions(+), 1 deletions(-)

diff --git a/Documentation/git.txt b/Documentation/git.txt
index 7310a2b..d243883 100644
--- a/Documentation/git.txt
+++ b/Documentation/git.txt
@@ -627,6 +627,9 @@ git Diffs
 
 other
 ~~~~~
+'GIT_PAGER'::
+	This environment variable overrides `$PAGER`.
+
 'GIT_TRACE'::
 	If this variable is set git will print `trace:` messages on
 	stderr telling about alias expansion, built-in command
diff --git a/pager.c b/pager.c
index 280f57f..dcb398d 100644
--- a/pager.c
+++ b/pager.c
@@ -15,11 +15,13 @@ void setup_pager(void)
 {
 	pid_t pid;
 	int fd[2];
-	const char *pager = getenv("PAGER");
+	const char *pager = getenv("GIT_PAGER");
 
 	if (!isatty(1))
 		return;
 	if (!pager)
+		pager = getenv("PAGER");
+	if (!pager)
 		pager = "less";
 	else if (!*pager || !strcmp(pager, "cat"))
 		return;
-- 
1.4.2.rc2.g91b7

```
