Skip to content

Commit

Permalink
Merge branch 'jn/pager-lv-default-env'
Browse files Browse the repository at this point in the history
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
  • Loading branch information
gitster committed Jan 13, 2014
2 parents 0a8cb03 + e54c1f2 commit 9fac077
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 3 deletions.
4 changes: 4 additions & 0 deletions Documentation/config.txt
Expand Up @@ -567,6 +567,10 @@ be passed to the shell by Git, which will translate the final
command to `LESS=FRSX less -+S`. The environment tells the command
to set the `S` option to chop long lines but the command line
resets it to the default to fold long lines.
+
Likewise, when the `LV` environment variable is unset, Git sets it
to `-c`. You can override this setting by exporting `LV` with
another value or setting `core.pager` to `lv +c`.

core.whitespace::
A comma separated list of common whitespace problems to
Expand Down
3 changes: 2 additions & 1 deletion git-sh-setup.sh
Expand Up @@ -159,7 +159,8 @@ git_pager() {
GIT_PAGER=cat
fi
: ${LESS=-FRSX}
export LESS
: ${LV=-c}
export LESS LV
eval "$GIT_PAGER" '"$@"'
}
Expand Down
11 changes: 9 additions & 2 deletions pager.c
Expand Up @@ -80,8 +80,15 @@ void setup_pager(void)
pager_process.use_shell = 1;
pager_process.argv = pager_argv;
pager_process.in = -1;
if (!getenv("LESS")) {
static const char *env[] = { "LESS=FRSX", NULL };
if (!getenv("LESS") || !getenv("LV")) {
static const char *env[3];
int i = 0;

if (!getenv("LESS"))
env[i++] = "LESS=FRSX";
if (!getenv("LV"))
env[i++] = "LV=-c";
env[i] = NULL;
pager_process.env = env;
}
if (start_command(&pager_process))
Expand Down
1 change: 1 addition & 0 deletions perl/Git/SVN/Log.pm
Expand Up @@ -117,6 +117,7 @@ sub run_pager {
}
open STDIN, '<&', $rfd or fatal "Can't redirect stdin: $!";
$ENV{LESS} ||= 'FRSX';
$ENV{LV} ||= '-c';
exec $pager or fatal "Can't run pager: $! ($pager)";
}

Expand Down
12 changes: 12 additions & 0 deletions t/t7006-pager.sh
Expand Up @@ -37,6 +37,18 @@ test_expect_failure TTY 'pager runs from subdir' '
test_cmp expected actual
'

test_expect_success TTY 'LESS and LV envvars are set for pagination' '
(
sane_unset LESS LV &&
PAGER="env >pager-env.out" &&
export PAGER &&
test_terminal git log
) &&
grep ^LESS= pager-env.out &&
grep ^LV= pager-env.out
'

test_expect_success TTY 'some commands do not use a pager' '
rm -f paginated.out &&
test_terminal git rev-list HEAD &&
Expand Down

0 comments on commit 9fac077

Please sign in to comment.