{"thread":{"id":"25328","subject":"Command specific pager settings","startedAt":"2010-10-04T07:37:29Z","lastAt":"2010-10-04T23:07:09Z","messageCount":3,"participants":["suvayu ali","Jeff King"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"152482","messageId":"AANLkTimLt0ERrB5b9p+_7fZBWfK3PHJkydmouiGfnurz@mail.gmail.com","threadId":"25328","inReplyTo":null,"subject":"Command specific pager settings","fromName":"suvayu ali","fromEmail":"fatkasuvayu+linux@gmail.com","sentAt":"2010-10-04T07:37:29Z","receivedAt":"2010-10-04T07:37:29Z","isPatch":false,"sender":{"key":"fatkasuvayu+linux@gmail.com","avatar":"https://gravatar.com/avatar/f1adf659f41e5846ddf6ab73bb474a3d9c29ac8ff8fa32adbf5796fc945096d0?d=mp&s=160"},"body":"Hi everyone,\n\nI am a new user of git and I was trying to configure the pager for git\nand ran across something. Is it possible to have different command\noptions to less for different git commands?\n\nI wanted to set my pager to `less -iRS' when looking at patches (so\nthat would mean commands like `git diff'), but would prefer `less\n-iFRS' or even the git default `less -FRSX' for all other things e.g\n`git log'.\n\nI looked at core.pager and pager.<cmd> but I couldn't understand how I\ncould set different pagers for say just one/ a subset of commands (git\ndiff in my case).\n\nIs this possible? If not, would it be a worthwhile feature request?\nThanks a lot for any pointers.\n\n-- \nSuvayu\n\nOpen source is the future. It sets us free.\n"},{"id":"152529","messageId":"20101004135312.GA11237@sigill.intra.peff.net","threadId":"25328","inReplyTo":"AANLkTimLt0ERrB5b9p+_7fZBWfK3PHJkydmouiGfnurz@mail.gmail.com","subject":"Re: Command specific pager settings","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2010-10-04T13:53:12Z","receivedAt":"2010-10-04T13:53:12Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Mon, Oct 04, 2010 at 12:37:29AM -0700, suvayu ali wrote:\n\n> I wanted to set my pager to `less -iRS' when looking at patches (so\n> that would mean commands like `git diff'), but would prefer `less\n> -iFRS' or even the git default `less -FRSX' for all other things e.g\n> `git log'.\n> \n> I looked at core.pager and pager.<cmd> but I couldn't understand how I\n> could set different pagers for say just one/ a subset of commands (git\n> diff in my case).\n> \n> Is this possible? If not, would it be a worthwhile feature request?\n\nIt's not currently possible, but this patch should do what you want,\nlike:\n\n  git config core.pager \"less -FRSX\"\n  git config pager.diff \"less -iRS\"\n\n-- >8 --\nSubject: [PATCH] allow command-specific pagers in pager.<cmd>\n\nA user may want different pager settings or even a\ndifferent pager for various subcommands (e.g., because they\nuse different less settings for \"log\" vs \"diff\", or because\nthey have a pager that interprets only log output but not\nother commands).\n\nThis patch extends the pager.<cmd> syntax to support not\nonly boolean to-page-or-not-to-page, but also to specify a\npager just for a specific command.\n\nSigned-off-by: Jeff King <peff@peff.net>\n---\n Documentation/config.txt |   12 +++++++-----\n git.c                    |   21 ++++++++++++++++-----\n t/t7006-pager.sh         |   29 +++++++++++++++++++++++++++++\n 3 files changed, 52 insertions(+), 10 deletions(-)\n\ndiff --git a/Documentation/config.txt b/Documentation/config.txt\nindex e6d74e6..458d2a4 100644\n--- a/Documentation/config.txt\n+++ b/Documentation/config.txt\n@@ -1527,11 +1527,13 @@ pack.packSizeLimit::\n \tsupported.\n \n pager.<cmd>::\n-\tAllows turning on or off pagination of the output of a\n-\tparticular git subcommand when writing to a tty.  If\n-\t`\\--paginate` or `\\--no-pager` is specified on the command line,\n-\tit takes precedence over this option.  To disable pagination for\n-\tall commands, set `core.pager` or `GIT_PAGER` to `cat`.\n+\tIf the value is boolean, turns on or off pagination of the\n+\toutput of a particular git subcommand when writing to a tty.\n+\tOtherwise, turns on pagination for the subcommand using the\n+\tpager specified by the value of `pager.<cmd>`.  If `\\--paginate`\n+\tor `\\--no-pager` is specified on the command line, it takes\n+\tprecedence over this option.  To disable pagination for all\n+\tcommands, set `core.pager` or `GIT_PAGER` to `cat`.\n \n pretty.<name>::\n \tAlias for a --pretty= format string, as specified in\ndiff --git a/git.c b/git.c\nindex 50a1401..7485a2d 100644\n--- a/git.c\n+++ b/git.c\n@@ -19,14 +19,22 @@ static struct startup_info git_startup_info;\n static int use_pager = -1;\n struct pager_config {\n \tconst char *cmd;\n-\tint val;\n+\tint want;\n+\tchar *value;\n };\n \n static int pager_command_config(const char *var, const char *value, void *data)\n {\n \tstruct pager_config *c = data;\n-\tif (!prefixcmp(var, \"pager.\") && !strcmp(var + 6, c->cmd))\n-\t\tc->val = git_config_bool(var, value);\n+\tif (!prefixcmp(var, \"pager.\") && !strcmp(var + 6, c->cmd)) {\n+\t\tint b = git_config_maybe_bool(var, value);\n+\t\tif (b >= 0)\n+\t\t\tc->want = b;\n+\t\telse {\n+\t\t\tc->want = 1;\n+\t\t\tc->value = xstrdup(value);\n+\t\t}\n+\t}\n \treturn 0;\n }\n \n@@ -35,9 +43,12 @@ int check_pager_config(const char *cmd)\n {\n \tstruct pager_config c;\n \tc.cmd = cmd;\n-\tc.val = -1;\n+\tc.want = -1;\n+\tc.value = NULL;\n \tgit_config(pager_command_config, &c);\n-\treturn c.val;\n+\tif (c.value)\n+\t\tpager_program = c.value;\n+\treturn c.want;\n }\n \n static void commit_pager_choice(void) {\ndiff --git a/t/t7006-pager.sh b/t/t7006-pager.sh\nindex fb744e3..49a6261 100755\n--- a/t/t7006-pager.sh\n+++ b/t/t7006-pager.sh\n@@ -435,4 +435,33 @@ test_core_pager_subdir    expect_success 'git -p shortlog'\n test_core_pager_subdir    expect_success test_must_fail \\\n \t\t\t\t\t 'git -p apply </dev/null'\n \n+test_expect_success TTY 'command-specific pager' '\n+\tunset PAGER GIT_PAGER;\n+\techo \"foo:initial\" >expect &&\n+\t>actual &&\n+\tgit config --unset core.pager &&\n+\tgit config pager.log \"sed s/^/foo:/ >actual\" &&\n+\ttest_terminal git log --format=%s -1 &&\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success TTY 'command-specific pager overrides core.pager' '\n+\tunset PAGER GIT_PAGER;\n+\techo \"foo:initial\" >expect &&\n+\t>actual &&\n+\tgit config core.pager \"exit 1\"\n+\tgit config pager.log \"sed s/^/foo:/ >actual\" &&\n+\ttest_terminal git log --format=%s -1 &&\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success TTY 'command-specific pager overridden by environment' '\n+\tGIT_PAGER=\"sed s/^/foo:/ >actual\" && export GIT_PAGER &&\n+\t>actual &&\n+\techo \"foo:initial\" >expect &&\n+\tgit config pager.log \"exit 1\" &&\n+\ttest_terminal git log --format=%s -1 &&\n+\ttest_cmp expect actual\n+'\n+\n test_done\n-- \n1.7.3.1.158.g6af003.dirty\n"},{"id":"152621","messageId":"AANLkTikDQfQPmk1i1vuydVf0yMAN45x+Q+q-yUr6i0=Y@mail.gmail.com","threadId":"25328","inReplyTo":"20101004135312.GA11237@sigill.intra.peff.net","subject":"Re: Command specific pager settings","fromName":"suvayu ali","fromEmail":"fatkasuvayu+linux@gmail.com","sentAt":"2010-10-04T23:07:09Z","receivedAt":"2010-10-04T23:07:09Z","isPatch":false,"sender":{"key":"fatkasuvayu+linux@gmail.com","avatar":"https://gravatar.com/avatar/f1adf659f41e5846ddf6ab73bb474a3d9c29ac8ff8fa32adbf5796fc945096d0?d=mp&s=160"},"body":"Hi Jeff,\n\nOn 4 October 2010 06:53, Jeff King <peff@peff.net> wrote:\n> On Mon, Oct 04, 2010 at 12:37:29AM -0700, suvayu ali wrote:\n>\n>> I wanted to set my pager to `less -iRS' when looking at patches (so\n>> that would mean commands like `git diff'), but would prefer `less\n>> -iFRS' or even the git default `less -FRSX' for all other things e.g\n>> `git log'.\n>>\n>> I looked at core.pager and pager.<cmd> but I couldn't understand how I\n>> could set different pagers for say just one/ a subset of commands (git\n>> diff in my case).\n>>\n>> Is this possible? If not, would it be a worthwhile feature request?\n>\n> It's not currently possible, but this patch should do what you want,\n> like:\n>\n>  git config core.pager \"less -FRSX\"\n>  git config pager.diff \"less -iRS\"\n>\n> -- >8 --\n> Subject: [PATCH] allow command-specific pagers in pager.<cmd>\n>\n> A user may want different pager settings or even a\n> different pager for various subcommands (e.g., because they\n> use different less settings for \"log\" vs \"diff\", or because\n> they have a pager that interprets only log output but not\n> other commands).\n>\n> This patch extends the pager.<cmd> syntax to support not\n> only boolean to-page-or-not-to-page, but also to specify a\n> pager just for a specific command.\n\nThis is exactly what I was hoping to achieve! However I use the git\npackages for my distro (Fedora 13), I'll keep a lookout for the\nupdates with your patch. Thank you soo much. :)\n\n-- \nSuvayu\n\nOpen source is the future. It sets us free.\n"}]}