How to wrap the zsh completion list with a fixed line of text before and after

autocompletezsh

Specifically, I'd like to arrange for all completion lists (under the :completion:* context) to be preceded and followed by a fixed string (say "ABC" for the moment) on its own line.

I have tried a variety of approaches, and I'm able to get the preceding line but not the following one. The best approaches are

  1. Use the array comppostfunc in _main_complete. Including a function that uses _message -r to print out the line. But comppostfun is executed at the end of _main_complete but apparently before the list is created, giving the string at the beginning not the end.

  2. Create new completers — a clone of _complete that returns 1 and a completer that just does _message. The idea being that the _message completer comes last.
    This works to a point but again the string comes at the beginning of the completion list.

  3. Adapt 1 or 2 by playing with the tag-order style to put messages at the end. This does not work.

  4. Create a variant of the _complete completer that does its normal action (_normal in one case) and ends with a _message. Again this does both but always puts the message first. Playing with tag-order does not change this.

I feel I'm missing something. For instance, is there a way to specify a completer style in which the output of several completers is concatenated? Why doesn't doing several actions within a completer produce the completion list in order? How to get tag-order style to put the _message output at the end?

Best Answer

The tag-order style does not change the order of the output. What you need to use is the group-order style. In addition, your beginning and end messages will need to have different group-names. See http://zsh.sourceforge.net/Doc/Release/Completion-System.html#Standard-Styles for more info.