Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Emulating 'locate'
- X-seq: zsh-users 6629
- From: Oliver Kiddle <okiddle@xxxxxxxxxxx>
- To: DervishD <raul@xxxxxxxxxxxx>
- Subject: Re: Emulating 'locate'
- Date: Thu, 02 Oct 2003 19:08:29 +0200
- Cc: Zsh Users <zsh-users@xxxxxxxxxx>
- In-reply-to: <20031002155306.GA26812@DervishD>
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- References: <20031001221753.GA23189@DervishD> <1031002023639.ZM22046@xxxxxxxxxxxxxxxxxxxxxxx> <20031002080358.GA23230@DervishD> <1031002142928.ZM22765@xxxxxxxxxxxxxxxxxxxxxxx> <20031002155306.GA26812@DervishD>
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
manually.
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.
Oliver
Messages sorted by:
Reverse Date,
Date,
Thread,
Author