[PATCH RFC] ui: introduce sysdefault section for pager and editor configuration
Jun Wu
quark at fb.com
Sun Mar 12 15:36:14 EDT 2017
What if instead of reading environments directly, introduce a new config
layer which is converted from environment variables? Like:
- (Top) layer: command line config flags
- layer: user configs
- layer: config converted from environment variables
like, convert "HGEDITOR" to "ui.editor"
- (Bottom) layer: system configs
In this way, we don't need a [sysdefault] and can just put things in /etc.
And that will solve other problems like:
<spectral> ryanmce's complaint to me yesterday was HGEDITOR=vim hg
--config ui.editor=true foo would run vim, even though editor is
'specified on command line'...
Excerpts from Augie Fackler's message of 2017-03-08 18:48:55 -0500:
> # HG changeset patch
> # User Augie Fackler <augie at google.com>
> # Date 1489016567 18000
> # Wed Mar 08 18:42:47 2017 -0500
> # Node ID 71fc64c48cfff1b7a2120c60e2b958da3263c0dc
> # Parent 92f7d6585c185e85763b3bad81b1304b8cdb5937
> ui: introduce sysdefault section for pager and editor configuration
>
> The debian package currently has to patch Mercurial to move the
> default editor from `vi` to `sensible-editor`. Now that we're growing
> another suboptimal-on-most-platforms default program (`more` as the
> pager), let's do packagers a small favor and give them a place where
> they can specify the default program for their platform, rather than
> having to rely on patching code during the build process. I'd expect
> the configuration on OS X to be something like:
>
> [sysdefault]
> editor = nano
> pager = LESS=FRX less
>
> and on debian to be:
>
> [sysdefault]
> editor = sensible-editor
> pager = sensible-pager
>
> diff --git a/mercurial/ui.py b/mercurial/ui.py
> --- a/mercurial/ui.py
> +++ b/mercurial/ui.py
> @@ -907,13 +907,11 @@ class ui(object):
> # HGPLAINEXCEPT=pager, and the user didn't specify --debug.
> return
>
> - # TODO: add a "system defaults" config section so this default
> - # of more(1) can be easily replaced with a global
> - # configuration file. For example, on OS X the sane default is
> - # less(1), not more(1), and on debian it's
> - # sensible-pager(1). We should probably also give the system
> - # default editor command similar treatment.
> - envpager = encoding.environ.get('PAGER', 'more')
> + # sysdefault.pager is available for packagers or system
> + # administrators to specify a saner default pager for their
> + # environment.
> + defaultpager = self.config('sysdefault', 'pager', default='more')
> + envpager = encoding.environ.get('PAGER', defaultpager)
> pagercmd = self.config('pager', 'pager', envpager)
> if not pagercmd:
> return
> @@ -1348,6 +1346,10 @@ class ui(object):
> editor = 'E'
> else:
> editor = 'vi'
> + # sysdefault.editor is available for packagers or system
> + # administrators to specify a saner default editor for their
> + # environment.
> + editor = self.config("sysdefault", "editor", default=editor)
> return (encoding.environ.get("HGEDITOR") or
> self.config("ui", "editor") or
> encoding.environ.get("VISUAL") or
More information about the Mercurial-devel
mailing list