0

I have a ZSH completer that provides the expected completions, but provides them in lexicographical order, as opposed to the order in which they were added via compadd:

_matcher_complete() {
  (git ls-files 2>/dev/null || find .) | /usr/local/bin/matcher -l20 ${words[CURRENT]} | while read line; do
    compadd -U "$line"
  done
  compstate[insert]=menu
}

zle -C matcher-complete complete-word _generic
zstyle ':completion:matcher-complete:*' completer _matcher_complete
zstyle ':completion:matcher-complete:*' menu-select

bindkey '^X^T' matcher-complete

How can I order the completions by insertion order?

paulmelnikow
  • 16,895
  • 8
  • 63
  • 114
Charles
  • 6,199
  • 6
  • 50
  • 66

1 Answers1

2

Using another ZSH completion script for inspiration, I changed the _matcher_complete function to the following:

_matcher_complete() {
  integer i=1
  (git ls-files 2>/dev/null || find .) | /usr/local/bin/matcher --limit 20 ${words[CURRENT]} | while read line; do
    compadd -U -2 -V $i -- "$line"
    i=$((i+1))
  done
  compstate[insert]=menu
}

Note the different args to compadd. I haven't had enough time to actually grok what each flag is doing (see man zshcompwid), but it appears you need to specify the order explicitly (thus the use of $i in the function above).

Assuming you have matcher installed, this code will give you fuzzy path completion ala Command-T/CtrlP.

Charles
  • 6,199
  • 6
  • 50
  • 66