From: Ray Andrews <rayandrews@eastlink.ca>
To: Zsh Users <zsh-users@zsh.org>
Subject: counting trouble
Date: Wed, 4 Apr 2018 11:21:17 -0700 [thread overview]
Message-ID: <469d8a16-69c9-79f2-bdce-467886913158@eastlink.ca> (raw)
I have a function that attempts a unique filename match for the argument
and warns you if what you have entered can't be disambiguated. It's
easy if there are multiple matcheswhich is of course 'unsuccessful' but
at least gives an honest report of the ambiguity:
tmp=( $1*(N) )
if [[ "$#tmp" > 1 ]]; then
echo "count is: $#tmp"
print -rl " More than one match:\n ${tmp[@]}\n"
fi
Alas, if there is only one match then the count becomes a countnot of
lines but of characterswhich is a nasty gotcha.
Hacking away I find this works:
[ -e "$1" ] && tmp=( "${(f)${1}}" ) || tmp=( ${1}*(N) )
...
... the first assignment forces the line count. But that's surely
monstrous. I've tried a single assignment but nothing seems legal as
far as getting the wildcard inside the '${(f) ...}' construction. I'd
have expected this to work: " ${(f)${1}*} " but it doesn't. Is something
civilized possible? I've sorta figured out that the wildcard is no
longer a wildcard in there, but what to do?
next reply other threads:[~2018-04-05 0:01 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-04-04 18:21 Ray Andrews [this message]
2018-04-05 1:15 ` Bart Schaefer
2018-04-05 2:07 ` Ray Andrews
2018-04-05 4:48 ` Bart Schaefer
2018-04-05 13:45 ` Ray Andrews
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=469d8a16-69c9-79f2-bdce-467886913158@eastlink.ca \
--to=rayandrews@eastlink.ca \
--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).