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

A minor syntax question



I am writing a function that's basically a wrapper to an invocation of
'find'. I have the need to transform some arguments to my function into an
expression I pass on to 'find'. Here's a simplified example of what I want
to do:

xff() {
    zparseopts -D -E t+:=types || return 1
    typearg="("${"$(print -- '-o -type '${^types:#-t})"#-o }")"
    print $typearg
}

What I want to do is to construct a nested expression for the variable
number of file types that can be given. They should be contained within
parenthesis, and joined by "-o". So, for example:

xff -t f   ->  "(-type f)"
xff -t f -t d   -> "(-type f -o -type d)"

As you can see, my function strips away the '-t' elements, then expands the
parameter list with '-o -type ' before each element, and finally strips
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.
At the same time, I'm rather happy with having found a one-liner expressing
what I want.

So my question is: is there a more elegant way of solving this which is
still compact?


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