From: "Jesper Nygårds" <jesper.nygards@gmail.com>
To: Zsh Users <zsh-users@zsh.org>
Subject: A minor syntax question
Date: Tue, 7 Jun 2016 08:58:59 +0200 [thread overview]
Message-ID: <CABZhJg8eEekK6hdrGY-2uTB9V6LF5JqkHPOpT6NXx=Gkeeb1HQ@mail.gmail.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 1174 bytes --]
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?
next reply other threads:[~2016-06-07 6:59 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-06-07 6:58 Jesper Nygårds [this message]
2016-06-07 11:54 ` Oliver Kiddle
2016-06-07 18:47 ` Jesper Nygårds
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CABZhJg8eEekK6hdrGY-2uTB9V6LF5JqkHPOpT6NXx=Gkeeb1HQ@mail.gmail.com' \
--to=jesper.nygards@gmail.com \
--cc=zsh-users@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).