Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: "rehash" but for autoloaded functions
- X-seq: zsh-users 28086
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: Zsh Users <zsh-users@xxxxxxx>
- Subject: Re: "rehash" but for autoloaded functions
- Date: Thu, 15 Sep 2022 12:07:09 -0700
- Archived-at: <https://zsh.org/users/28086>
- In-reply-to: <CAMP9c5k1xn59T+z-dSyQh0ZY=8borFYZfR_gzsbpjPwnijMZmA@mail.gmail.com>
- List-id: <zsh-users.zsh.org>
- References: <CAMP9c5k1xn59T+z-dSyQh0ZY=8borFYZfR_gzsbpjPwnijMZmA@mail.gmail.com>
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
sourced.
> 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