Passing options to "less" with the LESS environment variable can interfere with existing environment variables. There are at least two problems, as the following examples show:
1. Alice is using git with colors. Now she decides to set LESS=i for some reason. Suddenly, she sees codes in place of colors because LESS is no longer set automatically.
2. Bob sets GIT_PAGER="less -RS", but does not set LESS. Git sets LESS=FRSX before calling $GIT_PAGER. Now Bob wonders why his pager is not always paging, when he explicitly tried to clear the F option.
By passing the options on the command line instead, both of these situations are handled.
Signed-off-by: Anders Melchiorsen <mail@cup.kalibalik.dk> ---
Here is a resend, as I got no comments on the first try. The patch is rebased to the recent pager-swap setup.
For completeness, I note that this change will make existing setups with PAGER="less" behave differently, as they will no longer have -FRSX options set automatically. I tend to think that this is correct, since you then get what you ask for.
pager.c | 4 +--- 1 files changed, 1 insertions(+), 3 deletions(-)
Show changes to pager.c +1 −3
diff --git a/pager.c b/pager.c index aa0966c..9753fe9 100644 --- a/pager.c +++ b/pager.c @@ -20,8 +20,6 @@ static void pager_preexec(void) FD_ZERO(&in); FD_SET(0, &in); select(1, &in, NULL, &in, NULL); - - setenv("LESS", "FRSX", 0); } #endif @@ -52,7 +50,7 @@ void setup_pager(void) if (!pager) pager = getenv("PAGER"); if (!pager) - pager = "less"; + pager = "less -FRSX"; else if (!*pager || !strcmp(pager, "cat")) return;
-- 1.5.6.4