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

Re: Emulating 'locate'

DervishD wrote:

>     Well, the localoptions is for making option changes local, so
> options are restored ;) The nullglob and nocshnullglob are for making
> sure that zsh won't barf if no matches are found. In fact, something
> like this would be better for users:
>     locate () {
>         setopt localoptions nullglob nocshnullglob rcexpandparam
>         local -a matches
>         matches=(/**/*${*}*{,/**/*})
>         if [[ -z "$matches" ]]
>         then
>             print "Sorry, no matches found for '$*'"
>         else
>             print -l $matches
>         fi

What? So instead of zsh barfing on no matches, your script goes and
does the barfing for it: if I'm not missing the plot entirely here
you've basically just undone the effect of the nullglob options

You'd only want to do this if this locate() function is really part of
something bigger and the error message is indicating something really
is wrong. In which case you might want to send it to stderr with >&2.

There are good reasons why commands like locate and grep don't print
silly messages when nothing is found. The one useful improvement you
might make would be to return 1 if no matches are found. The zsh "no
matches found" error is a different case because the command isn't even
run: something that wouldn't otherwise be obvious.


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