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

completion based on context earlier in the line



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



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