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

counting trouble



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?




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