comparison mercurial/dispatch.py @ 13392:777cef34a890

dispatch: support for $ escaping in shell-alias definition Sigils in shell-alias can be escaped by doubling them.
author Roman Sokolov <sokolov.r.v@gmail.com>
date Fri, 11 Feb 2011 03:32:40 +0300
parents d747774ca9da
children d38d500deb08
comparison
equal deleted inserted replaced
13391:d00bbff8600e 13392:777cef34a890
219 if self.definition.startswith('!'): 219 if self.definition.startswith('!'):
220 self.shell = True 220 self.shell = True
221 def fn(ui, *args): 221 def fn(ui, *args):
222 env = {'HG_ARGS': ' '.join((self.name,) + args)} 222 env = {'HG_ARGS': ' '.join((self.name,) + args)}
223 def _checkvar(m): 223 def _checkvar(m):
224 if int(m.groups()[0]) <= len(args): 224 if m.groups()[0] == '$':
225 return m.group()
226 elif int(m.groups()[0]) <= len(args):
225 return m.group() 227 return m.group()
226 else: 228 else:
227 return '' 229 return ''
228 cmd = re.sub(r'\$(\d+)', _checkvar, self.definition[1:]) 230 cmd = re.sub(r'\$(\d+|\$)', _checkvar, self.definition[1:])
229 replace = dict((str(i + 1), arg) for i, arg in enumerate(args)) 231 replace = dict((str(i + 1), arg) for i, arg in enumerate(args))
230 replace['0'] = self.name 232 replace['0'] = self.name
231 replace['@'] = ' '.join(args) 233 replace['@'] = ' '.join(args)
232 cmd = util.interpolate(r'\$', replace, cmd) 234 cmd = util.interpolate(r'\$', replace, cmd, escape_prefix=True)
233 return util.system(cmd, environ=env) 235 return util.system(cmd, environ=env)
234 self.fn = fn 236 self.fn = fn
235 return 237 return
236 238
237 args = shlex.split(self.definition) 239 args = shlex.split(self.definition)