From 69bfdf4cfe1bb816300204c57b3fbffef4443faa Mon Sep 17 00:00:00 2001 From: Giuseppe Rota Date: Mon, 10 Mar 2014 10:49:52 +0100 Subject: [PATCH] Autocomplete for jc and jco --- bin/autojump | 6 +++--- bin/autojump.bash | 26 +++++++++++++++++++++++++- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/bin/autojump b/bin/autojump index eb24a63..f993087 100755 --- a/bin/autojump +++ b/bin/autojump @@ -202,9 +202,9 @@ def handle_tab_completion(needle, entries): print_local(tab_path) elif tab_index: get_ith_path = lambda i, iterable: last(take(i, iterable)).path - print_local(get_ith_path( - tab_index, - find_matches(entries, [tab_needle], check_entries=False))) + matches_from_index = find_matches(entries, [tab_needle], check_entries=False) + matching_path = get_ith_path(tab_index, matches_from_index) + print_local(matching_path) elif tab_needle: # found partial tab completion entry print_tab_menu( diff --git a/bin/autojump.bash b/bin/autojump.bash index 25a3ff3..827889b 100644 --- a/bin/autojump.bash +++ b/bin/autojump.bash @@ -29,8 +29,32 @@ _autojump() { $comps EOF } -complete -F _autojump j +complete -F _autojump j jo +_complete_autojump_c() { + local current_word + SAVE_IFS=$IFS + IFS=$'\n' + COMPREPLY=() + current_word="${COMP_WORDS[COMP_CWORD]}" + # tabbing on empty "prefix", e.g. jc + if [ -z "$current_word" ]; then + autocomplete_pattern="$PWD" + # tabbing when last item is a number jc /some/path.*first.*second__2 #FIXME? + elif [[ "$current_word" =~ ^[0-9]+$ ]]; then + autocomplete_pattern="${PWD}__$current_word" + # tabbing when last item contains .*, e.g. jc /some/path.*first.*second + elif [[ "$current_word" =~ .*\.\*.* ]]; then + autocomplete_pattern="$current_word" + # tabbing when there are tokens, e.g. jc first second + else + autocomplete_pattern="${PWD}.*${current_word}" + fi + comps=$(autojump --complete "$autocomplete_pattern") + COMPREPLY=($(compgen -W "$comps" --)) + IFS=$SAVE_IFS +} +complete -F _complete_autojump_c jc jco # change pwd hook autojump_add_to_database() {