[PATCH RFC] Do not override LESS

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

[PATCH RFC] Do not override LESS

Anders Melchiorsen
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 <[hidden email]>

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.

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"))
@@ -90,7 +90,6 @@ void setup_pager(void)
- setenv("LESS", "FRSX", 0);
  die("unable to execute pager '%s'", pager);

To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [hidden email]
More majordomo info at  http://vger.kernel.org/majordomo-info.html