* completion based on context earlier in the line
@ 2009-02-11 18:28 Danek Duvall
2009-02-11 18:39 ` Andrey Borzenkov
0 siblings, 1 reply; 3+ messages in thread
From: Danek Duvall @ 2009-02-11 18:28 UTC (permalink / raw)
To: zsh-workers
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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: completion based on context earlier in the line
2009-02-11 18:28 completion based on context earlier in the line Danek Duvall
@ 2009-02-11 18:39 ` Andrey Borzenkov
2009-02-11 19:10 ` [] " Danek Duvall
0 siblings, 1 reply; 3+ messages in thread
From: Andrey Borzenkov @ 2009-02-11 18:39 UTC (permalink / raw)
To: Danek Duvall, zsh-workers
[-- Attachment #1: Type: text/plain, Size: 2072 bytes --]
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 #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 197 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [] Re: completion based on context earlier in the line
2009-02-11 18:39 ` Andrey Borzenkov
@ 2009-02-11 19:10 ` Danek Duvall
0 siblings, 0 replies; 3+ messages in thread
From: Danek Duvall @ 2009-02-11 19:10 UTC (permalink / raw)
To: Andrey Borzenkov; +Cc: zsh-workers
On Wed, Feb 11, 2009 at 09:39:50PM +0300, Andrey Borzenkov wrote:
> You probably could use opt_args array:
Indeed. I'd tried that earlier, but thought I wasn't using it right, since
it was empty. Turns out I was doing
print ${(kv)opt_args}
which, with "-s sendmail" just put "sendmail" into the history a whole lot,
and didn't display anything. Oops.
Thanks,
Danek
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2009-02-11 19:10 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-02-11 18:28 completion based on context earlier in the line Danek Duvall
2009-02-11 18:39 ` Andrey Borzenkov
2009-02-11 19:10 ` [] " Danek Duvall
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).