* Command specific pager settings
@ 2010-10-04 7:37 suvayu ali
2010-10-04 13:53 ` Jeff King
0 siblings, 1 reply; 3+ messages in thread
From: suvayu ali @ 2010-10-04 7:37 UTC (permalink / raw)
To: git
Hi everyone,
I am a new user of git and I was trying to configure the pager for git
and ran across something. Is it possible to have different command
options to less for different git commands?
I wanted to set my pager to `less -iRS' when looking at patches (so
that would mean commands like `git diff'), but would prefer `less
-iFRS' or even the git default `less -FRSX' for all other things e.g
`git log'.
I looked at core.pager and pager.<cmd> but I couldn't understand how I
could set different pagers for say just one/ a subset of commands (git
diff in my case).
Is this possible? If not, would it be a worthwhile feature request?
Thanks a lot for any pointers.
--
Suvayu
Open source is the future. It sets us free.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Command specific pager settings
2010-10-04 7:37 Command specific pager settings suvayu ali
@ 2010-10-04 13:53 ` Jeff King
2010-10-04 23:07 ` suvayu ali
0 siblings, 1 reply; 3+ messages in thread
From: Jeff King @ 2010-10-04 13:53 UTC (permalink / raw)
To: suvayu ali; +Cc: Junio C Hamano, git
On Mon, Oct 04, 2010 at 12:37:29AM -0700, suvayu ali wrote:
> I wanted to set my pager to `less -iRS' when looking at patches (so
> that would mean commands like `git diff'), but would prefer `less
> -iFRS' or even the git default `less -FRSX' for all other things e.g
> `git log'.
>
> I looked at core.pager and pager.<cmd> but I couldn't understand how I
> could set different pagers for say just one/ a subset of commands (git
> diff in my case).
>
> Is this possible? If not, would it be a worthwhile feature request?
It's not currently possible, but this patch should do what you want,
like:
git config core.pager "less -FRSX"
git config pager.diff "less -iRS"
-- >8 --
Subject: [PATCH] allow command-specific pagers in pager.<cmd>
A user may want different pager settings or even a
different pager for various subcommands (e.g., because they
use different less settings for "log" vs "diff", or because
they have a pager that interprets only log output but not
other commands).
This patch extends the pager.<cmd> syntax to support not
only boolean to-page-or-not-to-page, but also to specify a
pager just for a specific command.
Signed-off-by: Jeff King <peff@peff.net>
---
Documentation/config.txt | 12 +++++++-----
git.c | 21 ++++++++++++++++-----
| 29 +++++++++++++++++++++++++++++
3 files changed, 52 insertions(+), 10 deletions(-)
diff --git a/Documentation/config.txt b/Documentation/config.txt
index e6d74e6..458d2a4 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -1527,11 +1527,13 @@ pack.packSizeLimit::
supported.
pager.<cmd>::
- Allows turning on or off pagination of the output of a
- particular git subcommand when writing to a tty. If
- `\--paginate` or `\--no-pager` is specified on the command line,
- it takes precedence over this option. To disable pagination for
- all commands, set `core.pager` or `GIT_PAGER` to `cat`.
+ If the value is boolean, turns on or off pagination of the
+ output of a particular git subcommand when writing to a tty.
+ Otherwise, turns on pagination for the subcommand using the
+ pager specified by the value of `pager.<cmd>`. If `\--paginate`
+ or `\--no-pager` is specified on the command line, it takes
+ precedence over this option. To disable pagination for all
+ commands, set `core.pager` or `GIT_PAGER` to `cat`.
pretty.<name>::
Alias for a --pretty= format string, as specified in
diff --git a/git.c b/git.c
index 50a1401..7485a2d 100644
--- a/git.c
+++ b/git.c
@@ -19,14 +19,22 @@ static struct startup_info git_startup_info;
static int use_pager = -1;
struct pager_config {
const char *cmd;
- int val;
+ int want;
+ char *value;
};
static int pager_command_config(const char *var, const char *value, void *data)
{
struct pager_config *c = data;
- if (!prefixcmp(var, "pager.") && !strcmp(var + 6, c->cmd))
- c->val = git_config_bool(var, value);
+ if (!prefixcmp(var, "pager.") && !strcmp(var + 6, c->cmd)) {
+ int b = git_config_maybe_bool(var, value);
+ if (b >= 0)
+ c->want = b;
+ else {
+ c->want = 1;
+ c->value = xstrdup(value);
+ }
+ }
return 0;
}
@@ -35,9 +43,12 @@ int check_pager_config(const char *cmd)
{
struct pager_config c;
c.cmd = cmd;
- c.val = -1;
+ c.want = -1;
+ c.value = NULL;
git_config(pager_command_config, &c);
- return c.val;
+ if (c.value)
+ pager_program = c.value;
+ return c.want;
}
static void commit_pager_choice(void) {
--git a/t/t7006-pager.sh b/t/t7006-pager.sh
index fb744e3..49a6261 100755
--- a/t/t7006-pager.sh
+++ b/t/t7006-pager.sh
@@ -435,4 +435,33 @@ test_core_pager_subdir expect_success 'git -p shortlog'
test_core_pager_subdir expect_success test_must_fail \
'git -p apply </dev/null'
+test_expect_success TTY 'command-specific pager' '
+ unset PAGER GIT_PAGER;
+ echo "foo:initial" >expect &&
+ >actual &&
+ git config --unset core.pager &&
+ git config pager.log "sed s/^/foo:/ >actual" &&
+ test_terminal git log --format=%s -1 &&
+ test_cmp expect actual
+'
+
+test_expect_success TTY 'command-specific pager overrides core.pager' '
+ unset PAGER GIT_PAGER;
+ echo "foo:initial" >expect &&
+ >actual &&
+ git config core.pager "exit 1"
+ git config pager.log "sed s/^/foo:/ >actual" &&
+ test_terminal git log --format=%s -1 &&
+ test_cmp expect actual
+'
+
+test_expect_success TTY 'command-specific pager overridden by environment' '
+ GIT_PAGER="sed s/^/foo:/ >actual" && export GIT_PAGER &&
+ >actual &&
+ echo "foo:initial" >expect &&
+ git config pager.log "exit 1" &&
+ test_terminal git log --format=%s -1 &&
+ test_cmp expect actual
+'
+
test_done
--
1.7.3.1.158.g6af003.dirty
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: Command specific pager settings
2010-10-04 13:53 ` Jeff King
@ 2010-10-04 23:07 ` suvayu ali
0 siblings, 0 replies; 3+ messages in thread
From: suvayu ali @ 2010-10-04 23:07 UTC (permalink / raw)
To: Jeff King; +Cc: Junio C Hamano, git
Hi Jeff,
On 4 October 2010 06:53, Jeff King <peff@peff.net> wrote:
> On Mon, Oct 04, 2010 at 12:37:29AM -0700, suvayu ali wrote:
>
>> I wanted to set my pager to `less -iRS' when looking at patches (so
>> that would mean commands like `git diff'), but would prefer `less
>> -iFRS' or even the git default `less -FRSX' for all other things e.g
>> `git log'.
>>
>> I looked at core.pager and pager.<cmd> but I couldn't understand how I
>> could set different pagers for say just one/ a subset of commands (git
>> diff in my case).
>>
>> Is this possible? If not, would it be a worthwhile feature request?
>
> It's not currently possible, but this patch should do what you want,
> like:
>
> git config core.pager "less -FRSX"
> git config pager.diff "less -iRS"
>
> -- >8 --
> Subject: [PATCH] allow command-specific pagers in pager.<cmd>
>
> A user may want different pager settings or even a
> different pager for various subcommands (e.g., because they
> use different less settings for "log" vs "diff", or because
> they have a pager that interprets only log output but not
> other commands).
>
> This patch extends the pager.<cmd> syntax to support not
> only boolean to-page-or-not-to-page, but also to specify a
> pager just for a specific command.
This is exactly what I was hoping to achieve! However I use the git
packages for my distro (Fedora 13), I'll keep a lookout for the
updates with your patch. Thank you soo much. :)
--
Suvayu
Open source is the future. It sets us free.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2010-10-04 23:07 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-10-04 7:37 Command specific pager settings suvayu ali
2010-10-04 13:53 ` Jeff King
2010-10-04 23:07 ` suvayu ali
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).