threads / rfc / 14781

RFC patchDo not override LESS

Subject: [PATCH RFC] Do not override LESS

## tl;dr

One message between Jul 31, 2008 and Jul 31, 2008. Diffs are folded; open one to read it.

replies: 0people: 1as markdown or json

Anders Melchiorsen· Jul 31, 2008, 22:00 UTC · lore

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, git displays codes in place of colors. Alice
likes codes, but she liked colors better!
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.
Maybe Mallory has been messing with something?

By passing the options on the command line instead, both of these situations are handled.

Signed-off-by: Anders Melchiorsen <mail@cup.kalibalik.dk>
---
There are at least two issues with this change:

A. Now /bin/sh will be executed all the time with the default pager. If this is perceived as a performance problem, I can make a special case.

B. This will make existing setups with PAGER="less" behave differently. They can, of course, be fixed with GIT_PAGER="less -FRSX".

I think that neither 1, 2, A or B are big problems. Nevertheless, I think this change makes things "more correct", so I hereby offer it for discussion.

Show changes to pager.c +1 −2
diff --git a/pager.c b/pager.c
index 6b5c9e4..232d6ed 100644
--- a/pager.c
+++ b/pager.c
@@ -60,7 +60,7 @@ void setup_pager(void)
 	if (!pager)
 		pager = getenv("PAGER");
 	if (!pager)
-		pager = "less";
+		pager = "less -FRSX";
 	else if (!*pager || !strcmp(pager, "cat"))
 		return;
 
@@ -90,7 +90,6 @@ void setup_pager(void)
 	close(fd[0]);
 	close(fd[1]);
 
-	setenv("LESS", "FRSX", 0);
 	run_pager(pager);
 	die("unable to execute pager '%s'", pager);
 	exit(255);
-- 
1.5.6.4

← back to recent threads