Skip to content

Commit

Permalink
Improve all matches completion
Browse files Browse the repository at this point in the history
  • Loading branch information
marlonrichert committed May 22, 2021
1 parent 62af5bd commit fe7c34a
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 12 deletions.
23 changes: 23 additions & 0 deletions completion/_autocomplete.all_matches
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#autoload

[[ -v _autocomplete__partial_list || $curcontext == *history* ]] &&
return 1

(( CURRENT > 1 && compstate[nmatches] > 1 )) ||
return

if [[ $_completer == expand ]]; then
_autocomplete.is_glob ||
return
else
[[ $words[1] != cd ]] ||
return
[[ -n $_comp_tags ]] ||
return
[[ -z ${${=_comp_tags}[@]:#((local-|)directories|((all|globbed)-|)files)} ]] ||
return
fi

local -a expl disp=( '' )
_description all-matches expl 'all matches'
compadd "$expl[@]" -d disp -C
13 changes: 10 additions & 3 deletions module/.autocomplete.async
Original file line number Diff line number Diff line change
Expand Up @@ -383,14 +383,21 @@ bindkey -s -M menuselect '^S' '^G^S'
fi

local -a _matches_=()
local -i header=$+_opts_[-X] footer=1 allinsert=2
local -i header=$+_opts_[-X] footer=0
[[ $IPREFIX$PREFIX$SUFFIX$ISUFFIX == *${compstate[unambiguous]:#?}* ]] &&
(( footer += 1 ))
( ( [[ $_completer == expand ]] && _autocomplete.is_glob ) ||
[[ $words[1] != cd &&
-z ${${=_comp_tags}[@]:#((local-|)directories|((all|globbed)-|)files)} ]] ) &&
(( footer += 2 ))
local -i lines_available=$((
max(0, _async_max_lines - header - footer - allinsert - compstate[list_lines])
max( 0, _async_max_lines - header - footer - compstate[list_lines] )
))
local -i ret number_of_new_matches lines_of_new_matches

if [[ -v _opts_[-D] ]]; then
.autocomplete.compadd "$@"; ret=$?
.autocomplete.compadd "$@"
ret=$?

[[ $funcstack[2] == _describe ]] ||
return ret
Expand Down
10 changes: 1 addition & 9 deletions module/.autocomplete.compinit
Original file line number Diff line number Diff line change
Expand Up @@ -127,15 +127,7 @@ EOF
_autocomplete._main_complete.post() {
compstate[list_max]=0
MENUSCROLL=0
if (( CURRENT > 1 && compstate[nmatches] > 1 )) && (
( [[ $_completer == expand ]] && _autocomplete.is_glob ) ||
[[ $words[1] != cd &&
$_comp_tags == *( (|-local)directories | (|(all|globbed)-)files ) ]]
); then
_description all-matches expl 'all matches'
compadd "$expl[@]" -C &&
_comp_tags+=' all-matches'
fi
_autocomplete.all_matches
_autocomplete.unambiguous
}

Expand Down

0 comments on commit fe7c34a

Please sign in to comment.