##// END OF EJS Templates
aliases: provide more flexible ways to work with shell alias arguments...
Steve Losh -
r11989:f853873f default
parent child Browse files
Show More
@@ -6,7 +6,7 b''
6 6 # GNU General Public License version 2 or any later version.
7 7
8 8 from i18n import _
9 import os, sys, atexit, signal, pdb, socket, errno, shlex, time, traceback
9 import os, sys, atexit, signal, pdb, socket, errno, shlex, time, traceback, re
10 10 import util, commands, hg, fancyopts, extensions, hook, error
11 11 import cmdutil, encoding
12 12 import ui as uimod
@@ -214,8 +214,18 b' class cmdalias(object):'
214 214
215 215 if self.definition.startswith('!'):
216 216 def fn(ui, *args):
217 cmd = '%s %s' % (self.definition[1:], ' '.join(args))
218 return util.system(cmd)
217 env = {'HG_ARGS': ' '.join((self.name,) + args)}
218 def _checkvar(m):
219 if int(m.groups()[0]) <= len(args):
220 return m.group()
221 else:
222 return ''
223 cmd = re.sub(r'\$(\d+)', _checkvar, self.definition[1:])
224 replace = dict((str(i + 1), arg) for i, arg in enumerate(args))
225 replace['0'] = self.name
226 replace['@'] = ' '.join(args)
227 cmd = util.interpolate(r'\$', replace, cmd)
228 return util.system(cmd, environ=env)
219 229 self.fn = fn
220 230 return
221 231
@@ -274,6 +284,9 b' class cmdalias(object):'
274 284 if self.shadows:
275 285 ui.debug("alias '%s' shadows command\n" % self.name)
276 286
287 if self.definition.startswith('!'):
288 return self.fn(ui, *args, **opts)
289 else:
277 290 return util.checksignature(self.fn)(ui, *args, **opts)
278 291
279 292 def addaliases(ui, cmdtable):
@@ -16,7 +16,13 b''
16 16 > dln = lognull --debug
17 17 > nousage = rollback
18 18 > put = export -r 0 -o "\$FOO/%R.diff"
19 > echo = !echo
19 > blank = !echo
20 > self = !echo '\$0'
21 > echo = !echo '\$@'
22 > echo1 = !echo '\$1'
23 > echo2 = !echo '\$2'
24 > echo13 = !echo '\$1' '\$3'
25 > count = !hg log -r '\$@' --template='.' | wc -c | sed -e 's/ //g'
20 26 > rt = root
21 27 >
22 28 > [defaults]
@@ -146,10 +152,35 b' path expanding'
146 152 +foo
147 153
148 154
149 shell aliases
155 simple shell aliases
156
157 $ hg blank
150 158
159 $ hg blank foo
160
161 $ hg echo
162
163 $ hg self
164 self
151 165 $ hg echo foo
152 166 foo
167 $ hg echo 'test $2' foo
168 test $2 foo
169 $ hg echo1 foo bar baz
170 foo
171 $ hg echo2 foo bar baz
172 bar
173 $ hg echo13 foo bar baz test
174 foo baz
175 $ hg echo2 foo
176
177 $ echo bar > bar
178 $ hg ci -qA -m bar
179 $ hg count .
180 1
181 $ hg count 'branch(default)'
182 2
183
153 184
154 185 invalid arguments
155 186
General Comments 0
You need to be logged in to leave comments. Login now