1
0
mirror of https://github.com/nvbn/thefuck.git synced 2024-10-06 02:41:10 +01:00

Slightly improve the fix_file rule

This commit is contained in:
mcarton 2015-08-26 19:57:34 +02:00
parent 51f1f44162
commit 9fc2bc904c

View File

@ -35,17 +35,17 @@ patterns = (
# for the sake of readability do not use named groups above # for the sake of readability do not use named groups above
def _make_pattern(pattern): def _make_pattern(pattern):
pattern = pattern.replace('{file}', '(?P<file>[^:\n]+)') pattern = pattern.replace('{file}', '(?P<file>[^:\n]+)') \
pattern = pattern.replace('{line}', '(?P<line>[0-9]+)') .replace('{line}', '(?P<line>[0-9]+)') \
pattern = pattern.replace('{col}', '(?P<col>[0-9]+)') .replace('{col}', '(?P<col>[0-9]+)')
return re.compile(pattern, re.MULTILINE) return re.compile(pattern, re.MULTILINE)
patterns = [_make_pattern(p) for p in patterns] patterns = [_make_pattern(p).search for p in patterns]
@memoize @memoize
def _search(stderr): def _search(stderr):
for pattern in patterns: for pattern in patterns:
m = re.search(pattern, stderr) m = pattern(stderr)
if m and os.path.isfile(m.group('file')): if m and os.path.isfile(m.group('file')):
return m return m