[PATCH] Allow templates to be found in user .hgtemplates directory

David Harrigan dharrigan at gmail.com
Wed Mar 31 15:52:01 CDT 2010


# HG changeset patch
# User David Harrigan <dharrigan at gmail.com>
# Date 1270068638 -7200
# Node ID ae8da26cbe5a2ba33e7134be4924c1e96bfb3654
# Parent  ef3668450cd0075978e2d11ec991aab557d9c59c
Allow templates to be found in user .hgtemplates directory.

This little patch permits the user to put templates into a .hgtemplates folder
in their home directory. If the user does not have permission to write to the
system install directory for mercurial, they can drop their templates in here.

for example:

~/.hgtemplates
    map-cmdline.nlog

then, they can do something like this:

[alias]
nlog = log --style nlog

diff --git a/mercurial/templater.py b/mercurial/templater.py
--- a/mercurial/templater.py
+++ b/mercurial/templater.py
@@ -9,7 +9,7 @@
 import re, sys, os
 import util, config, templatefilters
 
-path = ['templates', '../templates']
+path = ['templates', '../templates', '~/.hgtemplates']
 stringify = templatefilters.stringify
 
 def parsestring(s, quoted=True):
@@ -214,6 +214,8 @@
     for f in path:
         if f.startswith('/'):
             p = f
+        elif f.startswith('~'):
+            p = os.path.join(os.path.expanduser(f))
         else:
             fl = f.split('/')
             p = os.path.join(os.path.dirname(module), *fl)


More information about the Mercurial-devel mailing list