zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <p.w.stephenson@ntlworld.com>
To: <zsh-workers@zsh.org>
Subject: Re: How to do completion of toggle flag sequences separated by +/-
Date: Sun, 1 May 2011 17:18:46 +0100	[thread overview]
Message-ID: <20110501171846.7ea9607f@pws-pc.ntlworld.com> (raw)
In-Reply-To: <7965011ce0f14864142f9006d881bba9@ulrik.uio.no>

On Sun, 01 May 2011 12:16:05 +0200
Haakon Riiser <haakon.riiser@fys.uio.no> 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 <p.w.stephenson@ntlworld.com>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/


  reply	other threads:[~2011-05-01 16:19 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-05-01 10:16 Haakon Riiser
2011-05-01 16:18 ` Peter Stephenson [this message]
2011-05-02  9:16   ` Haakon Riiser
2011-05-03 10:27     ` Peter Stephenson
2011-05-03 13:49       ` Haakon Riiser

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20110501171846.7ea9607f@pws-pc.ntlworld.com \
    --to=p.w.stephenson@ntlworld.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).