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

Re: "rehash" but for autoloaded functions

On Thu, Sep 15, 2022 at 10:24 AM Zach Riggle <zachriggle@xxxxxxxxx> wrote:
> Is there an equivalent to "rehash" for autoloaded functions?

Presumably you mean functions that have already been loaded once, and
you want something to pick up the changes from disk?

Unfortunately once the function is loaded, there's no direct way to
determine HOW it was loaded.  You can find the file from which it was
loaded, but not whether that file was read from fpath or directly

> It's fine if they revert to being not-autoloaded-yet, just looking for a simple solution other than "exec zsh -il" to get this effect.

But "not-autoloaded-yet" does mean still marked for future autoload, right?

> I expect I can write something to this effect with "$functions_source[pip]" and compare the ${filename:t} to the function name, but I expect there's something for this already.

If you already know the name of the function(s) you want to "rehash"
this is easy; I have a little (also autoloaded) function:

reload() { unfunction $* ; autoload $* }

The tricky bit (where you might be able to use some sort of heuristic
on $functions_source) is finding the names of all functions that need
re-auto-loading.  This is more delicate than "rehash" (which simply
discards the entire command table) because you have to avoid
"unfunction"-ing anything that can't be re-"autoload"-ed.

That "reload" has been unchanged since zsh2.4, could probably stand
updating for some of the new options available to autoload.

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