Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Completions from file with zcompsys



On Jun 20,  8:46am, Dominik Vogt wrote:
}
} Are there some quick instructions instructions or a
} cheat sheet on the new completion system somewhere?

http://zsh.sourceforge.net/Guide/zshguide06.html#l144   (perhaps?)

} And I want to type things like
} 
}   $ foo Cheno<TAB>alb<TAB>   # -> Chenopodium album
}   $ foo Che*a<TAB>           # -> Chenopodium a
} 
} (using menu completion, not expanding the * to all matching
} completions).

The latter one could be tricky because you will have to prevent the "*"
from being expanded as a file glob.

Do you want the expansions exactly as you wrote them, or should the
spaces be quoted?  E.g. do you want to end up with something like one
of

    $ foo 'Chenopodium album'
    $ foo Chenopodium\ album          <-- this one is the easy one below

or instead

    $ foo Chenopodium album

?? The latter will be a bit more work because you will have to account
for the first word when completing the second word.

In any case, the procedure is to create a function that produces a list
of words and then passes them to the "compadd" builtin.  The list does
not have to be filtered against the command line (except in the "a bit
more work" case I just mentioned) because compadd will take care of
that part.  Then you pass the names of that function and of the command
to the "compdef" function.

You can also pass a string to be eval'd to compdef, so the simplest answer
to your question is (guessing at a file name)

    compdef 'compadd ${(f)"$(<~/latin-plant-names.txt)"}' foo

Then to get the "*"-expansion you will need to add the _match function
to your completer zstyle.  Example might be

    zstyle ':completion:*' completer _complete _match

but adjust the placement of _match to fit whatever your current list of
completers contains.  It would normally be anywhere after _complete.

If the above doesn't satisfy, we can go into more detail about how to
change or remove the quoting.



Messages sorted by: Reverse Date, Date, Thread, Author