zsh-workers
 help / color / mirror / code / Atom feed
From: Danek Duvall <duvall@comfychair.org>
To: zsh-workers@sunsite.dk
Subject: completion based on context earlier in the line
Date: Wed, 11 Feb 2009 10:28:08 -0800	[thread overview]
Message-ID: <20090211182808.GA20929@lorien.comfychair.org> (raw)

I'm having trouble figuring out how to do this.  I've got a command,
"svccfg", which can look roughly like:

    svccfg -s <service> describe <property>

I'm trying to figure out how to complete <property>, but it has to be based
on <service>, and I've no idea how to get the value of <service> to the
property completion function.

My _svccfg looks roughly like this (the full thing is in the zsh distro):

    if [[ $service == "svccfg" ]]; then
        _arguments -s \
            '-s[FMRI on which to operate]:fmri:_svcs_fmri -c' \
            <other options> \
            '*::command:->subcmd' && return 0

        if (( CURRENT == 1 )); then
            _wanted <subcommand completion>
            return
        fi

        service="$words[1]"
        curcontext=...
    fi

    case $service in
    (describe)
        _arguments -A "-*" \
            ":property:_smf_properties"

So I want to extract the argument to -s (if it exists) and pass it to
_smf_properties down below.  But I don't know how.  As above, by the time I
get past the first _arguments, $words no longer has any words prior to the
subcommand, so I can't go digging through there for it.  And my attempts to
use '*:command:->subcmd' (i.e., the single-colon version that doesn't reset
CURRENT and words) and emulate the double-colon version after extracting
the information have failed.  Perhaps I just haven't gotten it right yet.

I could do like _tar does, and check for the argument to -s before I even
get into the first _arguments, but that seems a bit sketchy, as I'd really
like to be sure to get the one before the subcommand, rather than any -s
flag that might happen after the subcommand.

Are there any examples I could crib from?  Can anyone offer any other help?

Thanks,
Danek


             reply	other threads:[~2009-02-11 18:28 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-02-11 18:28 Danek Duvall [this message]
2009-02-11 18:39 ` Andrey Borzenkov
2009-02-11 19:10   ` [] " Danek Duvall

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=20090211182808.GA20929@lorien.comfychair.org \
    --to=duvall@comfychair.org \
    --cc=zsh-workers@sunsite.dk \
    /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).