From 2a53341feb615df88489df3663993839472788a6 Mon Sep 17 00:00:00 2001 From: William Ting Date: Wed, 18 Dec 2013 16:11:05 -0600 Subject: [PATCH] finish partial tab match --- bin/autojump | 12 +++++++++--- bin/utils.py | 10 +++++++++- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/bin/autojump b/bin/autojump index 5a737fe..d1abd9f 100755 --- a/bin/autojump +++ b/bin/autojump @@ -45,6 +45,7 @@ from data import save from utils import decode from utils import encode_local from utils import first +from utils import get_needle from utils import get_needle_and_index from utils import get_pwd from utils import has_uppercase @@ -347,7 +348,7 @@ def main(): needle = first(needles) if is_tab_entry(needle, TAB_SEPARATOR): - # the needle is actually a tab entry here + # the needle is a tab_entry needle, tab_index = get_needle_and_index(needle, TAB_SEPARATOR) tab_entries = take( TAB_ENTRIES_COUNT, @@ -357,11 +358,16 @@ def main(): print(encode_local(surround_quotes( get_ith_path(tab_index, tab_entries)))) elif is_tab_partial_match(needle, TAB_SEPARATOR): - print("tab_partial_match") + # the needle is a partial tab_entry + needle = get_needle(needle, TAB_SEPARATOR) + tab_entries = take( + TAB_ENTRIES_COUNT, + find_matches(entriefy(load(config)), needle)) + print_tab_menu(needle, tab_entries, TAB_SEPARATOR) else: try: print(encode_local(surround_quotes( - first(find_matches(entries, needles)).path))) + first(find_matches(entries, needles)).path))) except AttributeError: # always return something so the calling shell function has an # argument to `cd` to diff --git a/bin/utils.py b/bin/utils.py index a1dcfc9..633e681 100644 --- a/bin/utils.py +++ b/bin/utils.py @@ -52,6 +52,15 @@ def first(xs): return None +def get_needle(tab_entry, separator): + """ + Given a partial tab entry in the following format return the needle: + + [needle]__ + """ + return re.match(r'(.*)'+separator, tab_entry).group(1) + + def get_needle_and_index(tab_entry, separator): """ Given a tab entry in the following format return the needle and index: @@ -66,7 +75,6 @@ def get_needle_and_index(tab_entry, separator): return matches.group(1), int(matches.group(2)) - def get_pwd(): try: return os.getcwdu()