git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[RFC] Clean way to disable pager

From
Matthieu Moy <matthieu.moy@imag.fr>
Date
Aug 19, 2007, 17:26 UTC
Message-ID
<vpq1wdz307k.fsf@bauges.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
Next: Matthieu Moy
Message 1 of 15 in “[RFC] Clean way to disable pager”
  1. Matthieu MoyAug 19, 2007
  2. Matthieu MoyAug 19, 2007
  3. Linus TorvaldsAug 19, 2007
  4. Brian GernhardtAug 19, 2007
  5. Junio C HamanoAug 19, 2007
  6. Matthieu MoyAug 19, 2007
  7. Adam RobenAug 19, 2007
  8. David KastrupAug 19, 2007
  9. Matthieu MoyAug 20, 2007
  10. Jakub NarebskiAug 21, 2007
  11. Replace git --paginate by git --pager[=PAGER_CMD].Matthieu Moy, Aug 21, 2007
  12. Johannes SchindelinAug 21, 2007
  13. Matthieu MoyAug 21, 2007
  14. David KastrupAug 21, 2007
  15. Alex RiesenAug 19, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.