diff --git a/bin/autojump b/bin/autojump index 399fed8..6ab7e09 100755 --- a/bin/autojump +++ b/bin/autojump @@ -47,7 +47,7 @@ from autojump_data import save from autojump_utils import decode from autojump_utils import encode_local from autojump_utils import first -from autojump_utils import get_tab_needle_and_path +from autojump_utils import get_tab_entry_info from autojump_utils import get_pwd from autojump_utils import has_uppercase from autojump_utils import is_osx @@ -185,11 +185,14 @@ def handle_tab_completion(needle, entries): if not needle: sys.exit(0) - tab_needle, path = get_tab_needle_and_path(needle, TAB_SEPARATOR) + tab_needle, tab_index, tab_path = get_tab_entry_info(needle, TAB_SEPARATOR) - if path: - # found complete tab completion entry - print(encode_local(path)) + if tab_path: + print(encode_local(tab_path)) + elif tab_index: + get_ith_path = lambda i, iterable: last(take(i, iterable)).path + print(encode_local( + get_ith_path(tab_index, find_matches(entries, tab_needle)))) elif tab_needle: # found partial tab completion entry print_tab_menu( @@ -363,11 +366,15 @@ def main(args): else: entries = entriefy(load(config)) needles = sanitize(args.directory) - _, path = get_tab_needle_and_path(first(needles), TAB_SEPARATOR) - - if path: - # found complete tab completion entry - print(encode_local(path)) + tab_needle, tab_index, tab_path = \ + get_tab_entry_info(first(needles), TAB_SEPARATOR) + + if tab_path: + print(encode_local(tab_path)) + elif tab_index: + get_ith_path = lambda i, iterable: last(take(i, iterable)).path + print(encode_local( + get_ith_path(tab_index, find_matches(entries, tab_needle)))) else: print(encode_local(first(find_matches(entries, needles)).path)) diff --git a/bin/autojump_utils.py b/bin/autojump_utils.py index 5221892..b8fee4a 100644 --- a/bin/autojump_utils.py +++ b/bin/autojump_utils.py @@ -59,28 +59,30 @@ def first(xs): return None -def get_tab_needle_and_path(tab_entry, separator): +def get_tab_entry_info(entry, separator): """ - Given a tab entry in the following format return the needle and path: + Given a tab entry in the following format return needle, index, and path: [needle]__[index]__[path] """ - match_needle = re.search(r'(.*?)' + separator, tab_entry) + needle, index, path = None, None, None + + match_needle = re.search(r'(.*?)' + separator, entry) + match_index = re.search(separator + r'([0-9]{1})', entry) match_path = re.search( separator + r'[0-9]{1}' + separator + r'(.*)', - tab_entry) + entry) if match_needle: - tab_needle = match_needle.group(1) - else: - tab_needle = None + needle = match_needle.group(1) + + if match_index: + index = int(match_index.group(1)) if match_path: path = match_path.group(1) - else: - path = None - return tab_needle, path + return needle, index, path def get_pwd():