From 015deece870452d36fa7e43e82c664ae8dcf4acc Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Wed, 25 Jun 2014 16:18:28 +0200 Subject: [PATCH] Completion and jumping for empty needles This adds support for `j ` and `j` without a needle to jump to the first/best match. Fixes https://github.com/joelthelion/autojump/issues/269 --- bin/autojump | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/bin/autojump b/bin/autojump index 0ad7ab9..d2577f8 100755 --- a/bin/autojump +++ b/bin/autojump @@ -193,9 +193,6 @@ def find_matches(entries, needles, check_entries=True): def handle_tab_completion(needle, entries): - if not needle: - sys.exit(0) - tab_needle, tab_index, tab_path = get_tab_entry_info(needle, TAB_SEPARATOR) if tab_path: @@ -364,7 +361,7 @@ def main(args): # noqa save(config, first(add_path(load(config), args.add))) elif args.complete: handle_tab_completion( - needle=first(sanitize(args.directory)), + needle=first(chain(sanitize(args.directory), [''])), entries=entriefy(load(config))) elif args.decrease: data, entry = decrease_path(load(config), get_pwd(), args.decrease) @@ -382,8 +379,12 @@ def main(args): # noqa elif args.stat: print_stats(load(config), config['data_path']) elif not args.directory: - # always return a path to calling shell functions - print_local('.') + # Return best match. + entries = entriefy(load(config)) + print_local(first(chain( + imap(attrgetter('path'), find_matches(entries, [''])), + # always return a path to calling shell functions + ['.']))) else: entries = entriefy(load(config)) needles = sanitize(args.directory)