Skip to content

Commit 9fac077

Browse files
committed
Merge branch 'jn/pager-lv-default-env'
Just like we give a reasonable default for "less" via the LESS environment variable, specify a reasonable default for "lv" via the "LV" environment variable when spawning the pager. * jn/pager-lv-default-env: pager: set LV=-c alongside LESS=FRSX
2 parents 0a8cb03 + e54c1f2 commit 9fac077

File tree

5 files changed

+28
-3
lines changed

5 files changed

+28
-3
lines changed

Documentation/config.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,10 @@ be passed to the shell by Git, which will translate the final
567567
command to `LESS=FRSX less -+S`. The environment tells the command
568568
to set the `S` option to chop long lines but the command line
569569
resets it to the default to fold long lines.
570+
+
571+
Likewise, when the `LV` environment variable is unset, Git sets it
572+
to `-c`. You can override this setting by exporting `LV` with
573+
another value or setting `core.pager` to `lv +c`.
570574

571575
core.whitespace::
572576
A comma separated list of common whitespace problems to

git-sh-setup.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,8 @@ git_pager() {
159159
GIT_PAGER=cat
160160
fi
161161
: ${LESS=-FRSX}
162-
export LESS
162+
: ${LV=-c}
163+
export LESS LV
163164
164165
eval "$GIT_PAGER" '"$@"'
165166
}

pager.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,15 @@ void setup_pager(void)
8080
pager_process.use_shell = 1;
8181
pager_process.argv = pager_argv;
8282
pager_process.in = -1;
83-
if (!getenv("LESS")) {
84-
static const char *env[] = { "LESS=FRSX", NULL };
83+
if (!getenv("LESS") || !getenv("LV")) {
84+
static const char *env[3];
85+
int i = 0;
86+
87+
if (!getenv("LESS"))
88+
env[i++] = "LESS=FRSX";
89+
if (!getenv("LV"))
90+
env[i++] = "LV=-c";
91+
env[i] = NULL;
8592
pager_process.env = env;
8693
}
8794
if (start_command(&pager_process))

perl/Git/SVN/Log.pm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ sub run_pager {
117117
}
118118
open STDIN, '<&', $rfd or fatal "Can't redirect stdin: $!";
119119
$ENV{LESS} ||= 'FRSX';
120+
$ENV{LV} ||= '-c';
120121
exec $pager or fatal "Can't run pager: $! ($pager)";
121122
}
122123

t/t7006-pager.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,18 @@ test_expect_failure TTY 'pager runs from subdir' '
3737
test_cmp expected actual
3838
'
3939

40+
test_expect_success TTY 'LESS and LV envvars are set for pagination' '
41+
(
42+
sane_unset LESS LV &&
43+
PAGER="env >pager-env.out" &&
44+
export PAGER &&
45+
46+
test_terminal git log
47+
) &&
48+
grep ^LESS= pager-env.out &&
49+
grep ^LV= pager-env.out
50+
'
51+
4052
test_expect_success TTY 'some commands do not use a pager' '
4153
rm -f paginated.out &&
4254
test_terminal git rev-list HEAD &&

0 commit comments

Comments
 (0)