Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Finally corrected the alias replacement loop.

  • Loading branch information...
commit e10b8c52ce701cc95b57360326f5cc43673d4c2d 1 parent 4ad7b72
@ghantoos authored
Showing with 20 additions and 7 deletions.
  1. +1 −0  CHANGES
  2. +19 −7 lshellmodule/lshell.py
View
1  CHANGES
@@ -29,6 +29,7 @@ http://sourceforge.net/projects/lshell/
the intro configuration field to "")
* Corrected multiple commands over ssh, and aliases interpretation.
* Added possibility to use wildcards in path definitions.
+ * Finally corrected the alias replacement loop.
=== v0.9.14 27/10/2010 ===
* Corrected get_aliases function, as it was looping when aliases were
View
26 lshellmodule/lshell.py
@@ -479,7 +479,7 @@ def check_path(self, line, completion=None, ssh=None, strict=None):
% tomatch)
return 1
else:
- return 1
+ return 1
if not completion:
if not re.findall(allowed_path_re, os.getcwd()+'/'):
if not ssh:
@@ -1410,17 +1410,29 @@ def __str__(self):
def get_aliases(line, aliases):
""" Replace all configured aliases in the line
"""
+
for item in aliases.keys():
- reg = '(^|; |;)%s([ ;&\|]+|$)' % item
- while re.findall(reg, line):
+ reg1 = '(^|; |;)%s([ ;&\|]+|$)(.*)' % item
+ reg2 = '(^|; |;)%s([ ;&\|]+|$)' % item
+
+ # in case aliase bigin with the same command
+ # (this is until i find a proper regex solution..)
+ if aliases[item].startswith(item):
+ aliaskey = os.urandom(10)
+
+ while re.findall(reg1, line):
+ (before, after, rest) = re.findall(reg1, line)[0]
linesave = line
- beforecommand = re.findall(reg, line)[0][0]
- aftercommand = re.findall(reg, line)[0][1]
- line = re.sub(reg, "%s%s%s" % (beforecommand, aliases[item], \
- aftercommand), line, 1)
+ cmd = "%s %s" % (item, rest)
+
+ line = re.sub(reg2, "%s%s%s" % (before, aliaskey, \
+ after), line, 1)
# if line does not change after sub, exit loop
if linesave == line:
break
+ # replace the key by the actual alias
+ line = line.replace(aliaskey, aliases[item])
+
for char in [';', '&', '|']:
# remove all remaining double char
line = line.replace('%s%s' %(char, char), '%s' %char)
Please sign in to comment.
Something went wrong with that request. Please try again.