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

Re: Feature request – substitutions similar to +, -, :+, :-



On Sat, Nov 18, 2017 at 10:22 AM, Sebastian Gniazdowski
<psprint@xxxxxxxxxxx> wrote:
>
> On 18 Nov 2017 at 19:05:25, Sebastian Gniazdowski (psprint@xxxxxxxxxxx) wrote:
> > echo "I'm ${${theme[use-name]:&Patrick}:-a subscriber}, hello."
>
> Just realized that with the description of :& I gave, this would work the same, except not only for "1", but any non-empty string:
>
> echo "I'm ${${theme[use-name]:+Patrick}:-a subscriber}
>
> So it's a matter of getting consensus on details of :& and :^.

If I understand your example correctly, $theme[use-name] is either
unset/empty, or it contains "1" or "0".

So I think :& is just  ${(M)theme[use-name]:#1} and :^ is ${theme[use-name]:#0}.

For $options, ${(M)options[...]:#on} and ${options[...]:#off}, so this
trick works with non-numeric booleans too.

You can do something similar with ${var/pat/repl} if you need to test
for substrings.



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