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

Re: completion based on context earlier in the line



On 11 of February 2009 21:28:08 Danek Duvall wrote:
> 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.

You probably could use opt_args array:

          In addition to $state, _arguments also sets the global
          parameters `context', `line' and `opt_args' as described
          below, and does not reset any changes made to the special
          parameters such as PREFIX and words.  This gives the calling
          function the choice of resetting these parameters or
          propagating changes in them.

     During the performance of the action the array `line' will be set
     to the command name and normal arguments from the command line,
     i.e. the words from the command line excluding all options and
     their arguments.  Options are stored in the associative array
     `opt_args' with option names as keys and their arguments as the
     values.  For options that have more than one argument these are
     given as one string, separated by colons.  All colons in the
     original arguments are preceded with backslashes.

Attachment: signature.asc
Description: This is a digitally signed message part.



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