zdharma-continuum / zinit

🌻 Flexible and fast ZSH plugin manager
MIT License
2.89k stars 124 forks source link

fix: assign to functions hash to make %x work #460

Closed psprint closed 1 year ago

psprint commented 1 year ago

The useful %x prompt expansion can be used to get path to the executed script: 0=${(%):-%x}

Description

It is always the correct, expected value, even for autoloaded functions. However, it currently doesn't work with Zinit special fpath-pollution free autoload. This patch fixes this.

Motivation and Context

It is comfortable to get correct $0 even for autoloaded functions with:

0=${(%):-%x}

However to make it fully work under Zinit, it has to define its emulated autoload function with:

functions[func]="…"

instead of:

eval "function func { …"

because the eval method returns wrong path at first function execution (returns path to name.plugin.zsh instead). That's the change of this PR.

How Has This Been Tested?

The change has to work, it's very isolated.

Types of changes

Checklist:

vladdoster commented 1 year ago

I can't quite tell what this fixes. Could you share a screenshot?

vladdoster commented 1 year ago

I thought it would fix the following issue at a cursory glance, but I guessed wrong.

Screenshot 2023-01-15 at 00 05 16
psprint commented 1 year ago

Here is the screenshot:

2023-01-15-131848_1904x789_scrot

vladdoster commented 1 year ago

@psprint,

I'm still unclear on what this fixes. Does it improve a certain ice, command, or just zsh programming in general?

psprint commented 1 year ago

It allows to use better $0 retriever code than the currently recommended in plugin standard. So maybe yes it improves zsh programming in general. I'll be writing a patch to the standard if the zinit problem will be fixed.

psprint commented 1 year ago

Could the PR be merged? It`s a very local, isolated change, basically a bug fix. To provide more info on what it does:

Is everything clear? I'm holding back because %x isn't fixed in Zinit, before updating the plugin standard, it's 0=… recommendation there.

psprint commented 1 year ago

Thanks for merging. Could some other my PRs be merged? Like those mentioned in #448 ?