I would like to do completion from a list of values that have ':' in them, something like: _values foo a::b c::d and have it offer 'a::b' and 'c::d' as choices, but I can't figure out how to escape the ':' in the completion system. Thanks, Scott
Scott Frazer wrote on Sat, 24 Aug 2019 12:44 +00:00: > I would like to do completion from a list of values that have ':' in > them, something like: > > _values foo a::b c::d > > and have it offer 'a::b' and 'c::d' as choices, but I can't figure out > how to escape the ':' in the completion system. Backslashes: [[[ % _f() { _values desc 'foo\:\:FOO' 'bar\:\:BAR' } % f <TAB> > desc bar::BAR foo::FOO % ]]] Cheers, Daniel
"Daniel Shahaf" wrote: > Scott Frazer wrote on Sat, 24 Aug 2019 12:44 +00:00: > > I would like to do completion from a list of values that have ':' in > > them, something like: > > > > _values foo a::b c::d > Backslashes: > > % _f() { _values desc 'foo\:\:FOO' 'bar\:\:BAR' } Or don't use _values: _wanted foos expl foo compadd a::b c::d Which particular feature of _values do you want? For lists, you can use _sequence, e.g.: _wanted foos expl foo _sequence compadd - a::b c::d and if you want descriptions, _describe might do the job but probably still needs colons to be quoted. _values is usually not the best choice when the list of matches are generated somehow. Oliver
On 8/24/2019 1:26 PM, Daniel Shahaf wrote:
> Scott Frazer wrote on Sat, 24 Aug 2019 12:44 +00:00:
>> I would like to do completion from a list of values that have ':' in
>> them, something like:
>>
>> _values foo a::b c::d
>>
>> and have it offer 'a::b' and 'c::d' as choices, but I can't figure out
>> how to escape the ':' in the completion system.
>
> Backslashes:
>
> [[[
> % _f() { _values desc 'foo\:\:FOO' 'bar\:\:BAR' }
> % f <TAB>
>> desc
> bar::BAR foo::FOO
> %
> ]]]
>
> Cheers,
>
> Daniel
>
Thanks, I thought I had tried all combinations of quotes and backslashes
but apparently not.
On 8/24/2019 9:18 PM, Oliver Kiddle wrote:
> "Daniel Shahaf" wrote:
>> Scott Frazer wrote on Sat, 24 Aug 2019 12:44 +00:00:
>>> I would like to do completion from a list of values that have ':' in
>>> them, something like:
>>>
>>> _values foo a::b c::d
>
>> Backslashes:
>>
>> % _f() { _values desc 'foo\:\:FOO' 'bar\:\:BAR' }
>
> Or don't use _values:
>
> _wanted foos expl foo compadd a::b c::d
>
> Which particular feature of _values do you want? For lists, you can use
> _sequence, e.g.:
> _wanted foos expl foo _sequence compadd - a::b c::d
>
> and if you want descriptions, _describe might do the job but probably
> still needs colons to be quoted. _values is usually not the best choice
> when the list of matches are generated somehow.
>
> Oliver
>
I guess I don't know which is most appropriate, there are many options
and _values seemed to fit the bill.
I pared things down for my question, but to be more exact I want
completion for an option. Something like:
_arguments : '--foo[Which foo to use]:foo:_values whatever 'a\:\:b' 'c\:\:d'
i.e. the --foo option has a limited number of legal values. What would
you suggest I use here?
Scott
On 26 Aug 2019, at 08:34, Scott Frazer <frazer.scott@gmail.com> wrote:
> _arguments : '--foo[Which foo to use]:foo:_values whatever 'a\:\:b' 'c\:\:d'
>
> i.e. the --foo option has a limited number of legal values. What would you
> suggest I use here?
If you're using _arguments you can just do like:
'--foo[specify foo to use]:foo:(a\:\:b c\:\:d)'
You can also use this syntax to give each value a description:
'--foo[specify foo to use]:foo:((
a\\\:\\\:b\:"ab foo"
c\\\:\\\:d\:"cd foo"
))'
Though it gets somewhat confusing when you have colons in the values, as you
can see
dana