From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 508 invoked by alias); 1 May 2011 16:19:11 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 29120 Received: (qmail 7510 invoked from network); 1 May 2011 16:18:59 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received-SPF: pass (ns1.primenet.com.au: SPF record at ntlworld.com designates 81.103.221.47 as permitted sender) Date: Sun, 1 May 2011 17:18:46 +0100 From: Peter Stephenson To: Subject: Re: How to do completion of toggle flag sequences separated by +/- Message-ID: <20110501171846.7ea9607f@pws-pc.ntlworld.com> In-Reply-To: <7965011ce0f14864142f9006d881bba9@ulrik.uio.no> References: <7965011ce0f14864142f9006d881bba9@ulrik.uio.no> X-Mailer: Claws Mail 3.7.8 (GTK+ 2.22.0; x86_64-redhat-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Cloudmark-Analysis: v=1.1 cv=JvdXmxIgLJv2/GthKqHpGJEEHukvLcvELVXUanXFreg= c=1 sm=0 a=EeDFCUyc0y0A:10 a=uObrxnre4hsA:10 a=kj9zAlcOel0A:10 a=NLZqzBF-AAAA:8 a=oOROeWC1VsoQ7G_hvtEA:9 a=CjuIK1q_8ugA:10 a=_dQi-Dcv4p4A:10 a=HpAAvcLHHh0Zw7uRqdWCyQ==:117 On Sun, 01 May 2011 12:16:05 +0200 Haakon Riiser wrote: > 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 (+) I don't think there's a prepackaged way of doing this. I've had some luck with the following. One thing it doesn't do is treat the + and - as separate from the options following, but a bit of patience might sort that out. It's actually written to complete options for the fictitious "flags" command, so you also have to insinuate it into ffmpeg completion somehow. #compdef flags # Attempt to get something that completes # +flag1+flag2-flag3 etc. _flag_options() { local expl _wanted options expl 'option' compadd -S '' -- {-,+}${^flag_options} } _more_flag_options() { compset -p $1 && _flag_options } _new_flag_options() { compset -P '*' && _flag_options } _flags() { local -a flag_options flag_options=(foo foobar bar) local match mbegin mend integer ret=1 if [[ $PREFIX = (#b)(*)[-+]([^-+]#) ]]; then if [[ -n ${flag_options[(R)$match[2]]} ]]; then _new_flag_options && ret=0 fi if [[ -n ${flag_options[(R)$match[2]?*]} ]]; then _more_flag_options ${#match[1]} && ret=0 fi else _flag_options && ret=0 fi return $ret } _flags "$@" -- Peter Stephenson Web page now at http://homepage.ntlworld.com/p.w.stephenson/