1
0
Fork 0

Alias module: handle special variable like $1, $2, ...

This commit is contained in:
nemunaire 2014-03-03 20:26:34 +01:00
parent 85fb612475
commit 073f34af26
1 changed files with 12 additions and 5 deletions

View File

@ -99,13 +99,20 @@ def cmd_unalias(msg):
def replace_variables(cnt, msg=None):
cnt = cnt.split(' ')
unsetCnt = list()
for i in range(0, len(cnt)):
res = re.match("^([^a-zA-Z0-9]*)(\\\\)\\$([a-zA-Z0-9]+)(.*)$", cnt[i])
if i not in unsetCnt:
res = re.match("^([^$]*)(\\\\)?\\$([a-zA-Z0-9]+)(.*)$", cnt[i])
if res is not None:
if res.group(2) != "":
cnt[i] = res.group(1) + "$" + res.group(3) + res.group(4)
else:
cnt[i] = res.group(1) + get_variable(res.group(3), msg) + res.group(4)
try:
varI = int(res.group(3))
unsetCnt.append(varI)
cnt[i] = res.group(1) + msg.cmds[varI] + res.group(4)
except:
if res.group(2) != "":
cnt[i] = res.group(1) + "$" + res.group(3) + res.group(4)
else:
cnt[i] = res.group(1) + get_variable(res.group(3), msg) + res.group(4)
return " ".join(cnt)