Both your examples work great, Oliver. Thank you.
Inspired by your second example I also found a solution which more closely
follows the way I have been thinking about the problem, and that I find
quite readable:
typearg="("${(j: -o :)${types:#-t}/#/-type }")"
On Tue, Jun 7, 2016 at 1:54 PM, Oliver Kiddle <okiddle@xxxxxxxxxxx> wrote:
> Jesper Nygårds wrote:
> > typearg="("${"$(print -- '-o -type '${^types:#-t})"#-o }")"
>
> > away the leading '-o'. It works as intended, but I feel it is more
> > complicated than required. In particular, I couldn't find a way to make
> the
> > '${^...}' parameter expansion trigger without the embedded print
> statement.
>
> Joining the array to form a string should avoid the need for a print,
> allowing the #-o to apply to the string as a whole. E.g:
>
> typearg=${${(j. .):-'-o -type '${^types:#-t}}#-o }
>
> Shorter versions should be possible such as the following:
>
> typearg="${${=types//-t/-o -type}[2,-1]}"
>
> I'd be inclined to keep typearg as an array, however.
>
> Oliver
>