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

Re: Emulating 'locate'



    Hi Bart :)

 * Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> dixit:
> } >     locate() { print -l /**/*${^*}*{,/**/*} }
> You might want:
>     locate() {
>        setopt localoptions nullglob nocshnullglob
>        print -l /**/*${^*}*{,/**/*}
>     }
> Do you see why?

    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

    }

    Thanks for your help :))

    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