Clean way to disable pager
RFC 1/1 Clean way to disable pager
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:
Quoted 1 line
From
2148c2564ca6480feaec9a9d091259032257918dMon Sep 17 00:00:00 2001
From: Matthieu Moy <[email protected]>
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(-)
Documentation/git.txt +5 -1
@@ -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.
git.c +1 -1
@@ -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" );Signature · 6 lines
1.5.3.rc0.64.gf4f4a-dirty -- Matthieu
Matthieu Moy, Sun, Aug 19, 2007 19:26:07 +0200:
Quoted 3 lines
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.
Quoted 3 lines · Matthieu Moy
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.
Quoted 8 lines
From
2148c2564ca6480feaec9a9d091259032257918dMon Sep 17 00:00:00 2001
From: Matthieu Moy <[email protected]>
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_PAGERto "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).
Quoted 4 lines · Junio C Hamano
Please resend an applyable patch with a sign-off (and acked-by as you have seen).
From
2c79b9a1b446ca9fa9d72fc595120da34fd403ddMon Sep 17 00:00:00 2001
From: Matthieu Moy <[email protected]>
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".
--- Documentation/git.txt | 6 +++++- git.c | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-)
Documentation/git.txt +5 -1
@@ -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.
git.c +1 -1
@@ -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" );Signature · 6 lines
1.5.3.rc0.64.gf4f4a-dirty -- Matthieu
Quoted 1 line · Matthieu Moy
+ [-p|--paginate] [--no-pager]
I think that [-p|--[no-]paginate] would be more consistent with the
way negatable options are normally specified.
-Adam
Quoted 6 lines · Adam Roben
Quoted 1 line · Matthieu Moy
+ [-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.
Signature · 1 line
David Kastrup, Kriemhildstr. 15, 44793 Bochum
Quoted 12 lines · David Kastrup
Quoted 6 lines · Adam Roben
Quoted 1 line · Matthieu Moy
+ [-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:
Quoted 6 lines
--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.
Signature · 1 line
Matthieu
Quoted 17 lines · Matthieu Moy
Quoted 16 lines · David Kastrup
Quoted 6 lines · Adam Roben
Quoted 1 line · Matthieu Moy
+ [-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
Quoted 8 lines
Quoted 1 line
"--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.
Signature · 3 lines
Jakub Narebski Warsaw, Poland ShadeHawk on #git
PATCH 1/1 Replace git --paginate by git --pager[=PAGER_CMD].
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.
--- Documentation/git.txt | 8 +++++--- git.c | 16 ++++++++++++++-- 2 files changed, 19 insertions(+), 5 deletions(-)
Documentation/git.txt +5 -3
@@ -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.
git.c +14 -2
@@ -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)
Signature · 1 line
1.5.3.rc5.17.g1cd0d-dirty
Re: [PATCH] Replace git --paginate by git --pager[=PAGER_CMD].
Hi,
Quoted 7 lines · Matthieu Moy
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
Re: [PATCH] Replace git --paginate by git --pager[=PAGER_CMD].
Quoted 3 lines · Johannes Schindelin
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"?
Signature · 1 line
Matthieu
Re: [PATCH] Replace git --paginate by git --pager[=PAGER_CMD].
Quoted 6 lines · Matthieu Moy
Quoted 3 lines · Johannes Schindelin
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.
Quoted 6 lines
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.
Signature · 1 line
David Kastrup
Quoted 3 lines · Matthieu Moy
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
Quoted 4 lines · Matthieu Moy
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
Quoted 2 lines · Matthieu Moy
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:
Documentation/git.txt +2 -1
@@ -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).
Signature · 1 line
Matthieu