@@ -191,6 +191,6 @@ def _newchgui(srcui, csystem, attachio):
return self._csystem(cmd, util.shellenviron(environ), cwd)
- def _runpager(self, cmd):
- self._csystem(cmd, util.shellenviron(), type='pager',
+ def _runpager(self, cmd, env=None):
+ self._csystem(cmd, util.shellenviron(env), type='pager',
cmdtable={'attachio': attachio})
return True
@@ -91,2 +91,8 @@ def rccomponents():
_rccomponents.extend(normpaths(userrcpath()))
return _rccomponents
+
+def defaultpagerenv():
+ '''return a dict of default environment variables and their values,
+ intended to be set before starting a pager.
+ '''
+ return {'LESS': 'FRX', 'LV': '-c'}
@@ -855,4 +855,9 @@ class ui(object):
return
+ pagerenv = {}
+ for name, value in rcutil.defaultpagerenv().items():
+ if name not in encoding.environ:
+ pagerenv[name] = value
+
self.debug('starting pager for command %r\n' % command)
self.flush()
@@ -861,5 +866,5 @@ class ui(object):
if util.safehasattr(signal, "SIGPIPE"):
signal.signal(signal.SIGPIPE, _catchterm)
- if self._runpager(pagercmd):
+ if self._runpager(pagercmd, pagerenv):
self.pageractive = True
# Preserve the formatted-ness of the UI. This is important
@@ -880,5 +885,5 @@ class ui(object):
self.disablepager()
- def _runpager(self, command):
+ def _runpager(self, command, env=None):
"""Actually start the pager and set up file descriptors.
@@ -913,5 +918,6 @@ class ui(object):
command, shell=shell, bufsize=-1,
close_fds=util.closefds, stdin=subprocess.PIPE,
- stdout=util.stdout, stderr=util.stderr)
+ stdout=util.stdout, stderr=util.stderr,
+ env=util.shellenviron(env))
except OSError as e:
if e.errno == errno.ENOENT and not shell:
@@ -255,2 +255,28 @@ Put annotate in the ignore list for page
9: a 9
10: a 10
+
+Environment variables like LESS and LV are set automatically:
+ $ cat > $TESTTMP/printlesslv.py <<EOF
+ > import os, sys
+ > sys.stdin.read()
+ > for name in ['LESS', 'LV']:
+ > sys.stdout.write(('%s=%s\n') % (name, os.environ.get(name, '-')))
+ > sys.stdout.flush()
+ > EOF
+
+ $ cat >> $HGRCPATH <<EOF
+ > [alias]
+ > noop = log -r 0 -T ''
+ > [ui]
+ > formatted=1
+ > [pager]
+ > pager = $PYTHON $TESTTMP/printlesslv.py
+ > EOF
+ $ unset LESS
+ $ unset LV
+ $ hg noop --pager=on
+ LESS=FRX
+ LV=-c
+ $ LESS=EFGH hg noop --pager=on
+ LESS=EFGH
+ LV=-c