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

How to do completion of toggle flag sequences separated by +/-

I'm still working on perfecting the FFmpeg completion function, and one of the most important things missing is good completion of toggle flags.

Here's an example of FFmpeg's toggle flag syntax:

ffmpeg -flags +gmc-global_header+cgop

In the above example, three toggle flags are set:

gmc is enabled (+)
global_header is disabled (-)
cgop is enabled (+)

Ideally, I would like the completion to behave like this:

ffmpeg -flags ^I

Typing the above should generate two matches: "+" and "-". Next,

ffmpeg -flags +^I

should generate a list of all possible flag values (gmc, cgop, etc). Next, select one of the flags, e.g.:

ffmpeg -flags +gmc^I

An important point here is that *no space should be inserted* after the inserted flag; the cursor must be placed immediately after "+gmc". Pressing TAB again should repeat the process by again suggesting "+" or "-" to add more flags. Once I'm done adding flags, I type in a space and completion should no longer be in toggle flag mode.

Achieving this seems very hard to do, because there could be ambiguity in some cases. Assume that "foo" and "foobar" are both valid flags, and I type this:

ffmpeg -flags +foo^I

Here, there are two possibilities: Either suggest "+" or "-" as if a new flag is to be completed (because +foo is a valid flag), or complete to +foobar because there is also a flag by that name. Resolving this is probably complicated, so I'll probably compromise on something. Does anyone have any suggestions on how to get as close to the above ideal completion behavior using standard zsh completion functions (_values, _arguments, etc)?


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