From 71861c4402ca5874e1d1457cd739c08cb67bdc5e Mon Sep 17 00:00:00 2001 From: William Ting Date: Tue, 17 Dec 2013 16:46:01 -0600 Subject: [PATCH] add tab completion printout --- bin/autojump | 22 +++++++++++----------- bin/utils.py | 10 ++++++++++ 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/bin/autojump b/bin/autojump index a8dd5a0..edc1ec7 100755 --- a/bin/autojump +++ b/bin/autojump @@ -50,12 +50,14 @@ from utils import has_uppercase from utils import is_osx from utils import last from utils import print_entry +from utils import print_tab_completion_menu from utils import second from utils import surround_quotes from utils import take VERSION = 'release-v21.8.0' FUZZY_MATCH_THRESHOLD = 0.6 +TAB_COMPLETION_COUNT = 9 def set_defaults(): @@ -102,12 +104,9 @@ def parse_arguments(): '-d', '--decrease', metavar='WEIGHT', nargs='?', type=int, const=15, default=False, help='decrease current directory weight') - # parser.add_argument( - # '-b', '--bash', action="store_true", default=False, - # help='enclose directory quotes to prevent errors') - # parser.add_argument( - # '--complete', action="store_true", default=False, - # help='used for tab completion') + parser.add_argument( + '--complete', action="store_true", default=False, + help='used for tab completion') parser.add_argument( '--purge', action="store_true", default=False, help='remove non-existent paths from database') @@ -287,8 +286,6 @@ def match_fuzzy(needles, haystack, ignore_case=False): def match_quicksilver(needles, haystack, ignore_case=False): - """ - """ return [] @@ -320,9 +317,12 @@ def main(): if args.add: save(config, first(add_path(load(config), args.add))) - # elif args.complete: - # config['match_cnt'] = 9 - # config['ignore_case'] = True + elif args.complete: + print_tab_completion_menu( + separator=config['tab_menu_separator'], + entries=take( + TAB_COMPLETION_COUNT, + find_matches(entriefy(load(config)), args.directory))) elif args.decrease: data, entry = decrease_path(load(config), get_pwd(), args.decrease) save(config, data) diff --git a/bin/utils.py b/bin/utils.py index 6f88750..166e44b 100644 --- a/bin/utils.py +++ b/bin/utils.py @@ -110,6 +110,16 @@ def print_entry(entry): print(encode_local("%.1f:\t%s" % (entry.weight, entry.path))) +def print_tab_completion_menu(separator, entries): + for i, entry in enumerate(entries): + print(encode_local(surround_quotes( + '%s%d%s%s' % ( + separator, + i, + separator, + entry.path)))) + + def second(xs): it = iter(xs) try: