mirror of
https://github.com/wting/autojump
synced 2024-10-27 20:34:07 +00:00
bugfix
This commit is contained in:
parent
3b5b52d610
commit
35836ada8f
15
autojump
15
autojump
@ -35,15 +35,16 @@ def uniqadd(list,key):
|
||||
def dicadd(dic,key,increment=1):
|
||||
dic[key]=dic.get(key,0.)+increment
|
||||
|
||||
def match(path,pattern,path_dict,re_flags=0):
|
||||
def match(path,pattern,path_dict,ignore_case=False):
|
||||
try:
|
||||
if os.path.realpath(os.curdir)==path : return False
|
||||
except OSError: #sometimes the current path doesn't exist anymore. In that case, jump if possible.
|
||||
pass
|
||||
match_string = "/".join(path.split('/')[-1-pattern.count('/'):])
|
||||
#import re
|
||||
#if re.search(pattern,match_string),re_flags) is None:
|
||||
if match_string.find(pattern) == -1:
|
||||
#if re.search(pattern,match_string),re.IGNORECASE if ignore_case else 0) is None:
|
||||
match=match_string.lower().find(pattern.lower()) == -1 if ignore_case else match_string.find(pattern) == -1
|
||||
if match:
|
||||
return False
|
||||
else:
|
||||
if os.path.exists(path) : return True
|
||||
@ -76,11 +77,11 @@ def forget(path_dict,dic_file):
|
||||
path_dict[k]*=0.9*max_keyweight/keyweight
|
||||
save(path_dict,dic_file)
|
||||
|
||||
def find_matches(dirs,pattern,path_dict,result_list,re_flags,max_matches):
|
||||
def find_matches(dirs,pattern,path_dict,result_list,ignore_case,max_matches):
|
||||
"""Find max_matches paths that match the pattern, and add them to the result_list"""
|
||||
for path,count in dirs:
|
||||
if len(result_list) >= max_matches : break
|
||||
if match(path,pattern,path_dict,re_flags):
|
||||
if match(path,pattern,path_dict,ignore_case):
|
||||
uniqadd(result_list,path)
|
||||
|
||||
def open_dic(dic_file,error_recovery=False):
|
||||
@ -145,11 +146,11 @@ else:
|
||||
|
||||
dirs=path_dict.items()
|
||||
dirs.sort(key=lambda e:e[1],reverse=True)
|
||||
find_matches(dirs,pattern,path_dict,results,re_flags=0,max_matches=9)
|
||||
find_matches(dirs,pattern,path_dict,results,False,max_matches=9)
|
||||
dirs=path_dict.items() #we need to recreate the list since the first iteration potentially deletes paths
|
||||
dirs.sort(key=lambda e:e[1],reverse=True)
|
||||
if completion or not results: #if not found, try ignoring case. On completion always show all results
|
||||
find_matches(dirs,pattern,path_dict,results,re_flags=re.IGNORECASE,max_matches=9)
|
||||
find_matches(dirs,pattern,path_dict,results,ignore_case=True,max_matches=9)
|
||||
if dead_dirs and not completion: #save the dict if there were some non-existent directories in the database
|
||||
save(path_dict,dic_file)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user