1
0
mirror of https://github.com/wting/autojump synced 2024-10-27 20:34:07 +00:00

Autocomplete for jc and jco

This commit is contained in:
Giuseppe Rota 2014-03-10 10:49:52 +01:00
parent 72313dbc51
commit 69bfdf4cfe
2 changed files with 28 additions and 4 deletions

View File

@ -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(

View File

@ -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 <tab>
if [ -z "$current_word" ]; then
autocomplete_pattern="$PWD"
# tabbing when last item is a number jc /some/path.*first.*second__2<tab> #FIXME?
elif [[ "$current_word" =~ ^[0-9]+$ ]]; then
autocomplete_pattern="${PWD}__$current_word"
# tabbing when last item contains .*, e.g. jc /some/path.*first.*second<tab>
elif [[ "$current_word" =~ .*\.\*.* ]]; then
autocomplete_pattern="$current_word"
# tabbing when there are tokens, e.g. jc first second<tab>
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() {