mirror of
https://github.com/wting/autojump
synced 2024-10-27 20:34:07 +00:00
first match case, then try to ignore it
This commit is contained in:
parent
1d09620baa
commit
1d73eeee6c
14
autojump.py
14
autojump.py
@ -22,10 +22,10 @@ max_keyweight=1000
|
|||||||
def dicadd(dic,key,increment=1):
|
def dicadd(dic,key,increment=1):
|
||||||
dic[key]=dic.get(key,0.)+increment
|
dic[key]=dic.get(key,0.)+increment
|
||||||
|
|
||||||
def match(path,pattern,path_dict):
|
def match(path,pattern,path_dict,re_flags=0):
|
||||||
import re
|
import re
|
||||||
if os.path.realpath(os.curdir)==path : return False
|
if os.path.realpath(os.curdir)==path : return False
|
||||||
if re.search(pattern,"/".join(path.split('/')[-1-pattern.count('/'):]),re.IGNORECASE) is None:
|
if re.search(pattern,"/".join(path.split('/')[-1-pattern.count('/'):]),re_flags) is None:
|
||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
if os.path.exists(path) : return True
|
if os.path.exists(path) : return True
|
||||||
@ -63,10 +63,18 @@ else:
|
|||||||
if not args: args=['']
|
if not args: args=['']
|
||||||
dirs=path_dict.items()
|
dirs=path_dict.items()
|
||||||
dirs.sort(key=lambda e:e[1],reverse=True)
|
dirs.sort(key=lambda e:e[1],reverse=True)
|
||||||
|
import re
|
||||||
|
found=False
|
||||||
for path,count in dirs:
|
for path,count in dirs:
|
||||||
if match(path," ".join(args),path_dict):
|
if match(path," ".join(args),path_dict): #First look for case-matching path
|
||||||
print path
|
print path
|
||||||
|
found=True
|
||||||
break
|
break
|
||||||
|
if not found:
|
||||||
|
for path,count in dirs:
|
||||||
|
if match(path," ".join(args),path_dict,re.IGNORECASE): #Then try to ignore case
|
||||||
|
print path
|
||||||
|
break
|
||||||
cPickle.dump(path_dict,open(dic_file+".tmp",'w'),-1)
|
cPickle.dump(path_dict,open(dic_file+".tmp",'w'),-1)
|
||||||
import shutil
|
import shutil
|
||||||
shutil.copy(dic_file+".tmp",dic_file) #cPickle.dump doesn't seem to be atomic, so this is more secure
|
shutil.copy(dic_file+".tmp",dic_file) #cPickle.dump doesn't seem to be atomic, so this is more secure
|
||||||
|
Loading…
Reference in New Issue
Block a user