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

Re: Emulating 'locate'

    Hi Oliver :))

 * Oliver Kiddle <okiddle@xxxxxxxxxxx> dixit:
> >     locate () {
> 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.

    Not exactly. I've replaced a message like 'zsh: no matches found:
/**/*whatever*...' by a simple 'Sorry I didn't found whatever'. This
*is* intended, because I was writing a locate emulation for end users
(just for fun, I must admit, but for end users...). I didn't had in
mind using this function in pipelines or complex commands.

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

    You are completely right.
> There are good reasons why commands like locate and grep don't print
> silly messages when nothing is found.

    I can think of one right now: if you use it in a command
substitution, you really don't want your file list, for example,
being 'grep: arse! cannot find your effin regex'... Yes, obviously
the less I could do with the function above is redirecting the
message to stderr, my mistake O:))

    Anyway I don't use 'locate' in pipelines or command substitution,
so I didn't think about this situation. Thanks for pointing.

> The one useful improvement you
> might make would be to return 1 if no matches are found.

    Yes, this would be a good idea, thanks a lot :)) And I must admit
- painfully ;)) - that it would be even better than a message.

    Raúl Núñez de Arenas Coronado

Linux Registered User 88736
http://www.pleyades.net & http://raul.pleyades.net/

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