Scenario:
Let's say a script my_online_searcher <query>
opens a browser with the search for query
, where query
can be multiple words long. This same script also provides a utility flag -s <query>
that shows the search engine's suggestions. E.g.:
$ my_online_searcher -s lion rema
lion remake
lion remake cast
lion remake zoo tycoon 2
lion remake zt2
remake lion king
remastered lion's share
remake lion king 2019
remastered lion king
remake lion king trailer
remaking lion king
Desired outcome:
The user would type $ my_online_searcher lion rema[TAB]
and ZSH completion menu would give the above options.
Attempts to achieve desired outcome:
Create a little completions script _my_online_searcher
that pretty much calls the my_online_search -s <query>
support function to give out options. Something like:
[...]
completions=(${(f)"$(my_online_searcher -s ${arg} ${words:2})"})
_describe 'suggestions' completions
[...]
This allows for the spaces to be escaped and allow ZSH to see the query
as a single argument.
However, a per-word completion does not allow the progressive completion of the suggestions. Either it repeats the previous words, or filters out suggestions that do not begin with the first arguments (e.g. $ my_online searcher lion rema[TAB]
-> $ my_online_searcher lion remake lion king
).
One idea was to modify the LBUFFER
inside the completion script. This turned out to not be allowed as ZSH gives the error that LBUFFER
is readonly
TL;DR:
Is it possible to have ZSH completion system see all the arguments after the command as a modifiable argument? In other words, can I propose completions to multiple arguments at the same time in ZSH?