zsh-users
 help / color / mirror / code / Atom feed
* Completing comma seprated list of option values in _atguments
@ 2002-02-22 12:14 Borsenkow Andrej
  2002-02-25  8:54 ` Sven Wischnowsky
  0 siblings, 1 reply; 4+ messages in thread
From: Borsenkow Andrej @ 2002-02-22 12:14 UTC (permalink / raw)
  To: 'Zsh users list'

I must be entirely stupid but I cannot figure out how to do it. Values
must be generated on the fly not chosen from fixed array. And _values
seems to want fixed values only :(

-andrej


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Completing comma seprated list of option values in _atguments
  2002-02-22 12:14 Completing comma seprated list of option values in _atguments Borsenkow Andrej
@ 2002-02-25  8:54 ` Sven Wischnowsky
  2002-02-25  9:22   ` Borsenkow Andrej
  2002-02-25  9:54   ` Oliver Kiddle
  0 siblings, 2 replies; 4+ messages in thread
From: Sven Wischnowsky @ 2002-02-25  8:54 UTC (permalink / raw)
  To: zsh-users


Borsenkow Andrej wrote:

> I must be entirely stupid but I cannot figure out how to do it. Values
> must be generated on the fly not chosen from fixed array. And _values
> seems to want fixed values only :(

Yes, _values is not intended for that, although it depends on how the
values are generated, of course...

We probably don't need utility functions for everything, simple
solution, not that nice, but ok when values may appear more than once:

  local expl

  compset -P '*,'
  _wanted foos expl foo compadd -qS, calculated values

More sophisticated, values may appear only once:

  local expl comps suf

  comps=(value calculation goes here)

  compset -P '*,'
  comps=( ${comps:#${~IPREFIX//,/|}} )

  if [[ $#comps -gt 1 ]]; then
    suf=(-qS,)
  else
    suf=()
  fi

  _wanted foos expl foo compadd $suf $comps

If you want to generate the matches even later, I'd suggest using the
first version with _wanted calling a utility function that builds the
matches. But if those values are the only possible matches in that
context and hence are the normal completions in that case it's
probably not worth it and the code above should be enough.


Bye
  Sven

-- 
Sven Wischnowsky                          wischnow@berkom.de


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Completing comma seprated list of option values in _atguments
  2002-02-25  8:54 ` Sven Wischnowsky
@ 2002-02-25  9:22   ` Borsenkow Andrej
  2002-02-25  9:54   ` Oliver Kiddle
  1 sibling, 0 replies; 4+ messages in thread
From: Borsenkow Andrej @ 2002-02-25  9:22 UTC (permalink / raw)
  To: Sven Wischnowsky; +Cc: zsh-users

On Пнд, 2002-02-25 at 11:54, Sven Wischnowsky wrote:
> 
> Borsenkow Andrej wrote:
> 
> > I must be entirely stupid but I cannot figure out how to do it. Values
> > must be generated on the fly not chosen from fixed array. And _values
> > seems to want fixed values only :(
> 
> Yes, _values is not intended for that, although it depends on how the
> values are generated, of course...
> 
> We probably don't need utility functions for everything, simple
> solution, not that nice, but ok when values may appear more than once:
> 

I finally ended up with

_urpmi_media() {
    local source media brace ret=1 opt
    local -a all_sources
    local context state line
    typeset -A val_args
    while read source media brace; do
        [[ "$brace" != "{" ]] && continue
        all_sources=($all_sources $source)
    done < /etc/urpmi/urpmi.cfg
    if [[ "$service" == urpmq ]]; then
        _values -s , "urpmi media"  "$all_sources[@]" && ret=0
    else
        _wanted urpmi_media expl 'available media' \
            compadd "$@" -a -- all_sources && ret=0
    fi
    return ret
}

but may be I can omit _values just as well, besides it seems to be buggy
at this point.

thanks

-andrej



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Completing comma seprated list of option values in _atguments
  2002-02-25  8:54 ` Sven Wischnowsky
  2002-02-25  9:22   ` Borsenkow Andrej
@ 2002-02-25  9:54   ` Oliver Kiddle
  1 sibling, 0 replies; 4+ messages in thread
From: Oliver Kiddle @ 2002-02-25  9:54 UTC (permalink / raw)
  To: Sven Wischnowsky, zsh-users

 --- Sven Wischnowsky <wischnow@berkom.de> wrote:

>   compset -P '*,'
>   _wanted foos expl foo compadd -qS, calculated values

Though this and the example which followed it don't really handle a
suffix. I'd stick compset -S ',*' || suf=(-qS,) between those two
lines.

I'd use _values here though unless you're coming up against bugs.

Oliver


__________________________________________________
Do You Yahoo!?
Everything you'll ever need on one web page
from News and Sport to Email and Music Charts
http://uk.my.yahoo.com


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2002-02-25  9:54 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-02-22 12:14 Completing comma seprated list of option values in _atguments Borsenkow Andrej
2002-02-25  8:54 ` Sven Wischnowsky
2002-02-25  9:22   ` Borsenkow Andrej
2002-02-25  9:54   ` Oliver Kiddle

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).