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

Re: Emulating 'locate'



Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> writes:

> On Oct 4,  3:33pm, Lloyd Zusman wrote:
> }
> } [ ... ]
> }
> For certain searches, "find -depth" might actually be faster.  Zsh
> always does breadth-first globbing, even when asked to sort the final
> results depth-first.

I guess that comes into play when I want to find something that happens
to be buried deep inside of a directory tree, where the parents directories
have lots of files.


> } [ ... ]
> } 
> } Well, using this alias causes the argv indices to be off by one in the
> } shell function: $0 becomes 'noglob', argv[1] becomes 'xlocate', etc.
>
> If you're seeing that, then you've accidentally created a function named
> "noglob" that has the same body as "xlocate".  Try this:
>
> 	alias foo='bar foo'
> 	foo() { echo $0 }
> 	functions bar
> 	functions foo
>
> Note that "foo()" is considered to be "in the command position" and thus
> the alias expands and you get
>
> 	bar foo () { echo $0 }
>
> which defines two functions, "bar" and "foo" with identical bodies.  I'd
> wager that you created the alias, then changed the definition of xlocate,
> and ended up with a function named "noglob".

Yep.  That's exactly what happened.  Thank you.  I kept re-invoking
". /etc/zshrc" to test some changes to my function as I was developing
it.  The alias command "alias xlocate='noglob xlocate'" was then in
effect the next time I sourced /etc/zshrc.

Therefore, prior to the function definition, I now do this:

  { unalias xlocate; unfunction xlocate } 2>/dev/null

But besides that, would another way to prevent this problem be to always
define functions with "function foo" instead of "foo()"?


-- 
 Lloyd Zusman
 ljz@xxxxxxxxxx



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