From e1ee1724379a0ea9bdaba24838a2e3f0bd5d8a59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=ABl=20Schaerer?= Date: Wed, 7 Sep 2011 13:24:24 +0200 Subject: [PATCH 1/3] attempt to fix completion of weird directory names --- autojump | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/autojump b/autojump index 502b917..46bd8da 100755 --- a/autojump +++ b/autojump @@ -224,7 +224,7 @@ def shell_utility(): if not completion and clean_dict(dirs, path_dict): save(path_dict, dic_file) - if completion and ('--bash', '') in optlist: quotes = '"' + if completion and ('--bash', '') in optlist: quotes = "'" else: quotes = "" if userchoice != -1: From b2985f3255c87d10708f8fef3dfae81bba2948a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=ABl=20Schaerer?= Date: Fri, 9 Sep 2011 13:04:21 +0200 Subject: [PATCH 2/3] "Eat" paths to avoid multiple patterns matching the same part of the string example: if you have /tmp/vv/vv and want to specifically target it, you can now type j vv vv and it won't match /tmp/vv. --- autojump | 49 +++++++++++++++++++++++++++++++------------------ 1 file changed, 31 insertions(+), 18 deletions(-) diff --git a/autojump b/autojump index 46bd8da..05b9a5c 100755 --- a/autojump +++ b/autojump @@ -93,36 +93,49 @@ def clean_dict(sorted_dirs, path_dict): else: return False def match(path, pattern, ignore_case=False, only_end=False): - """Check whether a path matches a particular pattern""" - try: - if os.path.realpath(os.curdir) == path : - return False - #Sometimes the current path doesn't exist anymore. - #In that case, jump if possible. - except OSError: - pass + """Check whether a path matches a particular pattern, and return + the remaning part of the string""" if only_end: match_string = "/".join(path.split('/')[-1-pattern.count('/'):]) else: match_string = path if ignore_case: - does_match = (match_string.lower().find(pattern.lower()) != -1) + find_idx = match_string.lower().find(pattern.lower()) + else: + find_idx = match_string.find(pattern) + does_match = (find_idx != -1) + # Eat the path to avoid two patterns matching the same part of the string + if does_match: + eaten_path = path[find_idx+len(pattern):] else: - does_match = (match_string.find(pattern) != -1) - #return True if there is a match and the path exists - #(useful in the case of external drives, for example) - return does_match and os.path.exists(path) + eaten_path = path + return (does_match, eaten_path) def find_matches(dirs, patterns, 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 - #For the last pattern, only match the end of the pattern - if all(match(path, p, ignore_case, - only_end=(n == len(patterns)-1)) for n, p in enumerate(patterns)): + # Don't jump to where we alread are + try: + if os.path.realpath(os.curdir) == path : + continue + #Sometimes the current path doesn't exist anymore. + #In that case, jump if possible. + except OSError: + pass + #If a path doesn't exist, don't jump there + #We still keep it in db in case it's from a removable drive + if not os.path.exists(path): + continue + does_match, eaten_path = True, path + for n,p in enumerate(patterns): + #For the last pattern, only match the end of the pattern + does_match, eaten_path = match(eaten_path, p, ignore_case, only_end=(n == len(patterns)-1)) + if not does_match: break + if does_match: uniqadd(result_list, path) + if len(result_list) >= max_matches : + break def open_dic(dic_file, error_recovery=False): """Try hard to open the database file, recovering From a4f4472046d4cf384f4e713fb6ce312c0b0fe3c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=ABl=20Schaerer?= Date: Fri, 9 Sep 2011 13:04:35 +0200 Subject: [PATCH 3/3] Send error message to stderr --- autojump | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/autojump b/autojump index 05b9a5c..7b3aaf4 100755 --- a/autojump +++ b/autojump @@ -171,7 +171,7 @@ def shell_utility(): optlist, args = getopt.getopt(argv[1:], 'a', ['stat', 'import', 'completion', 'bash']) except getopt.GetoptError as ex: - print("Unknown command line argument: %s" % ex) + print("Unknown command line argument: %s" % ex, file=stderr) exit(1) dic_file = get_dic_file()