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

Re: Can this snippet be further improved?

On Fri, 28 Jul 2023 at 16:38, Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
> On Fri, Jul 28, 2023 at 3:07 AM Sebastian Gniazdowski
> <sgniazdowski@xxxxxxxxx> wrote:
> > >     0=${${ZERO:-${(%):-%x}}:A}
> What is $ZERO ?  (I'm not very familiar with the "zsh plugin standard" here.)

ZERO is a $0-like variable however provided by the plugin manager. If
a plugin supports it then it may be easily loaded in an non-standard
way, like eval "$(<plugin-file.zsh):" (a faster method, however if the
script is compiled, then dot/source wins,so it's controversial…),

> Is there a reason not to use ${funcstack[1]} instead of ${(%):-%x} ?
> I presume you're assigning 0= at top level of the plugin, otherwise %x
> is going to be the file where the function is defined rather than the
> file where the function is being executed and further you'd mess up
> FUNCTIONARGZERO et al.  I suppose %x doesn't require zsh/parameter, is
> that really an issue?

I think that the returning of origin source file is a plus – one can
throw in the 0="…" snippet in any kind of file, hash-bang script,
sourced script and autoload function and always get expected result. I
think that if it'll be called in a function defined inside the sourced
script, then it'll still return the same, correct file path.

> As to :A vs. :P, it almost seems like :a:P would be preferable to
> either of those ... :A is described as ":a followed by realpath()
> except where there is no realpath(3)" whereas :P is "LIKE realpath()"
> but doesn't actually require realpath(3).

Thanks, it seems to clarify the :A and :P difference, I'll go for :P then.

Best regards,
Sebastian Gniazdowski

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