zsh-users
 help / color / mirror / code / Atom feed
* "rehash" but for autoloaded functions
@ 2022-09-15 17:24 Zach Riggle
  2022-09-15 19:07 ` Bart Schaefer
  0 siblings, 1 reply; 2+ messages in thread
From: Zach Riggle @ 2022-09-15 17:24 UTC (permalink / raw)
  To: Zsh Users

[-- Attachment #1: Type: text/plain, Size: 503 bytes --]

Is there an equivalent to "rehash" for autoloaded functions?

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.

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 not, where can I find instructions on how to contribute something like
this upstream, e.g. rehash_functions?

*Zach Riggle*

[-- Attachment #2: Type: text/html, Size: 822 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: "rehash" but for autoloaded functions
  2022-09-15 17:24 "rehash" but for autoloaded functions Zach Riggle
@ 2022-09-15 19:07 ` Bart Schaefer
  0 siblings, 0 replies; 2+ messages in thread
From: Bart Schaefer @ 2022-09-15 19:07 UTC (permalink / raw)
  To: Zsh Users

On Thu, Sep 15, 2022 at 10:24 AM Zach Riggle <zachriggle@gmail.com> 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.


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-09-15 19:08 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-15 17:24 "rehash" but for autoloaded functions Zach Riggle
2022-09-15 19:07 ` Bart Schaefer

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).