diff --git a/bin/autojump b/bin/autojump index 3431eec..bf1443d 100755 --- a/bin/autojump +++ b/bin/autojump @@ -65,7 +65,7 @@ from autojump_utils import sanitize from autojump_utils import take from autojump_utils import unico -VERSION = '22.3.2' +VERSION = '22.3.3' FUZZY_MATCH_THRESHOLD = 0.6 TAB_ENTRIES_COUNT = 9 TAB_SEPARATOR = '__' diff --git a/bin/autojump_match.py b/bin/autojump_match.py index 088e8bf..5549e1b 100644 --- a/bin/autojump_match.py +++ b/bin/autojump_match.py @@ -2,11 +2,14 @@ # -*- coding: utf-8 -*- import os import re -import sys from difflib import SequenceMatcher +from autojump_utils import is_python3 +from autojump_utils import is_windows +from autojump_utils import last -if sys.version_info[0] == 3: + +if is_python3(): ifilter = filter imap = map os.getcwdu = os.getcwd @@ -73,7 +76,7 @@ def match_consecutive(needles, haystack, ignore_case=False): regex_no_sep_end = regex_no_sep + '$' regex_one_sep = regex_no_sep + sep + regex_no_sep # can't use compiled regex because of flags - regex_needle = regex_one_sep.join(map(re.escape, needles)).replace('\\', '\\\\') + regex_no_sep_end # noqa + regex_needle = regex_one_sep.join(imap(re.escape, needles)).replace('\\', '\\\\') + regex_no_sep_end # noqa regex_flags = re.IGNORECASE | re.UNICODE if ignore_case else re.UNICODE found = lambda entry: re.search( regex_needle, @@ -82,10 +85,10 @@ def match_consecutive(needles, haystack, ignore_case=False): return ifilter(found, haystack) -def match_fuzzy(needles, haystack, ignore_case=False): +def match_fuzzy(needles, haystack, ignore_case=False, threshold=0.6): """ Performs an approximate match with the last needle against the end of - every path past an acceptable threshold (FUZZY_MATCH_THRESHOLD). + every path past an acceptable threshold. For example: needles = ['foo', 'bar'] @@ -115,6 +118,5 @@ def match_fuzzy(needles, haystack, ignore_case=False): match_percent = lambda entry: SequenceMatcher( a=needle, b=end_dir(entry.path)).ratio() - meets_threshold = lambda entry: match_percent(entry) >= \ - FUZZY_MATCH_THRESHOLD + meets_threshold = lambda entry: match_percent(entry) >= threshold return ifilter(meets_threshold, haystack)