config: add initial implementation of --edit

This launches the preferred editor on either:

a) the first non-empty user rc file found
b) the first user rc file in the search list
This commit is contained in:
Matt Mackall 2014-02-27 13:46:32 -06:00
parent 8e74d42689
commit 6b078f60b5
2 changed files with 16 additions and 2 deletions

View File

@ -1462,7 +1462,8 @@ def commit(ui, repo, *pats, **opts):
cmdutil.commitstatus(repo, node, branch, bheads, opts)
@command('config|showconfig|debugconfig',
[('u', 'untrusted', None, _('show untrusted configuration options'))],
[('u', 'untrusted', None, _('show untrusted configuration options')),
('e', 'edit', None, _('start editor'))],
_('[-u] [NAME]...'))
def config(ui, repo, *values, **opts):
"""show combined config settings from all hgrc files
@ -1481,6 +1482,19 @@ def config(ui, repo, *values, **opts):
Returns 0 on success.
"""
if opts.get('edit'):
paths = scmutil.userrcpath()
for f in paths:
if os.path.exists(f):
break
else:
f = paths[0]
editor = ui.geteditor()
util.system("%s \"%s\"" % (editor, f),
onerr=util.Abort, errprefix=_("edit failed"),
out=ui.fout)
return
for f in scmutil.rcpath():
ui.debug('read config from: %s\n' % f)
untrusted = bool(opts.get('untrusted'))

View File

@ -222,7 +222,7 @@ Show all commands + options
branches: active, closed
bundle: force, rev, branch, base, all, type, ssh, remotecmd, insecure
cat: output, rev, decode, include, exclude
config: untrusted
config: untrusted, edit
copy: after, force, include, exclude, dry-run
debugancestor:
debugbuilddag: mergeable-file, overwritten-file, new-file