1
0
mirror of https://github.com/wting/autojump synced 2024-10-27 20:34:07 +00:00

move match last pattern into separate funciton and disabled

This commit is contained in:
William Ting 2012-05-06 13:51:18 -10:00
parent 31001c9456
commit 7343ef1825

View File

@ -34,6 +34,7 @@ class Database:
self.data = {}
self.load()
# TODO: increase logarithmically as opposed to linear
def add(self, key, increment = 1):
""" Increment existing paths or initialize new ones to 0. """
self.data[key] = self.data.get(key, 0.) + increment
@ -207,6 +208,19 @@ def unico(text):
else:
return unicode(text)
def match_last(pattern):
""" If the last pattern contains a full path, jump there.
The regexp is because we need to support stuff like
"j wo jo__3__/home/joel/workspace/joel" for zsh. """
last_pattern_path = re.sub("(.*)"+COMPLETION_SEPARATOR, "", pattern[-1])
if (len(last_pattern_path) > 0 and
last_pattern_path[0] == "/" and
os.path.exists(last_pattern_path)):
if not ARGS.preserve:
output(last_pattern_path)
return True
return False
def match(path, pattern, ignore_case=False, only_end=False):
""" Check whether a path matches a particular pattern, and return
the remaining part of the string. """
@ -250,24 +264,20 @@ def shell_utility():
options()
db = Database(DB_FILE)
#userchoice is i if the pattern is __pattern__i, otherwise -1
userchoice = -1
results = []
# if no directories, add empty string
if (ARGS.directory == ''):
patterns = [unico('')]
else:
patterns = [decode(a) for a in ARGS.directory]
# If the last pattern contains a full path, jump there
# The regexp is because we need to support stuff like
# "j wo jo__3__/home/joel/workspace/joel" for zsh
last_pattern_path = re.sub("(.*)"+COMPLETION_SEPARATOR, "", patterns[-1])
if (len(last_pattern_path)>0 and
last_pattern_path[0] == "/" and
os.path.exists(last_pattern_path)):
if not ARGS.complete: output(last_pattern_path)
else:
# check last pattern for full path
# FIXME: disabled until tab completion is fixed on the shell side
# if match_last(patterns): return True
#userchoice is i if the pattern is __pattern__i, otherwise -1
userchoice = -1
results = []
#check for ongoing completion, and act accordingly
endmatch = re.search(COMPLETION_SEPARATOR+"([0-9]+)", patterns[-1])
if endmatch: #user has selected a completion