mirror of
https://github.com/wting/autojump
synced 2024-10-27 20:34:07 +00:00
add regex exact match
This commit is contained in:
parent
fdeedb4f70
commit
f84dffb7c7
24
bin/autojump
24
bin/autojump
@ -30,6 +30,7 @@ from operator import attrgetter
|
|||||||
from operator import itemgetter
|
from operator import itemgetter
|
||||||
import os
|
import os
|
||||||
import platform
|
import platform
|
||||||
|
from re import search
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from argparse import ArgumentParser
|
from argparse import ArgumentParser
|
||||||
@ -197,15 +198,28 @@ def find_matches(config, needles, count=1):
|
|||||||
sanitize = lambda x: decode(x).rstrip(os.sep)
|
sanitize = lambda x: decode(x).rstrip(os.sep)
|
||||||
needles = imap(sanitize, needles)
|
needles = imap(sanitize, needles)
|
||||||
|
|
||||||
exact_matches = data
|
exact_matches = match_exact_regex(needles, data)
|
||||||
for needle in needles:
|
|
||||||
exact_matches = match_exact(needle, exact_matches)
|
|
||||||
|
|
||||||
return first(exact_matches).path
|
return first(exact_matches).path
|
||||||
|
|
||||||
|
|
||||||
def match_exact(needle, haystack):
|
def match_exact_regex(needles, haystack):
|
||||||
find = lambda haystack: needle in haystack.path
|
"""
|
||||||
|
Performs an exact match by combining all arguments into a single regex
|
||||||
|
expression and finding matches.
|
||||||
|
|
||||||
|
For example:
|
||||||
|
needles = ['qui', 'fox']
|
||||||
|
regex needle = r'.*qui.*fox.*'
|
||||||
|
haystack = [
|
||||||
|
(path="foobar", 10.0),
|
||||||
|
(path="The quick brown fox jumped over the lazy dog", 12.3)]
|
||||||
|
|
||||||
|
result = [(path="The quick brown fox jumped over the lazy dog", 12.3)]
|
||||||
|
"""
|
||||||
|
|
||||||
|
regex_needle = '.*' + '.*'.join(needles) + '.*'
|
||||||
|
find = lambda haystack: search(regex_needle, haystack.path)
|
||||||
return ifilter(find, haystack)
|
return ifilter(find, haystack)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user