changeset 20572:c724cb0141ee

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
author Matt Mackall <mpm@selenic.com>
date Thu, 27 Feb 2014 13:46:32 -0600
parents d4893e64f300
children 02d0d3aa42e3
files mercurial/commands.py tests/test-completion.t
diffstat 2 files changed, 16 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/commands.py	Wed Feb 26 18:56:27 2014 -0800
+++ b/mercurial/commands.py	Thu Feb 27 13:46:32 2014 -0600
@@ -1462,7 +1462,8 @@
     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 @@
     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'))
--- a/tests/test-completion.t	Wed Feb 26 18:56:27 2014 -0800
+++ b/tests/test-completion.t	Thu Feb 27 13:46:32 2014 -0600
@@ -222,7 +222,7 @@
   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