zsh-users
 help / color / mirror / code / Atom feed
* counting trouble
@ 2018-04-04 18:21 Ray Andrews
  2018-04-05  1:15 ` Bart Schaefer
  0 siblings, 1 reply; 5+ messages in thread
From: Ray Andrews @ 2018-04-04 18:21 UTC (permalink / raw)
  To: Zsh Users

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?



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2018-04-05 13:45 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-04 18:21 counting trouble Ray Andrews
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

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).