geometry-zsh / geometry

geometry is a minimal, fully customizable and composable zsh prompt theme
ISC License
931 stars 94 forks source link

feat: function lazy loading. #273

Closed alxbl closed 4 years ago

alxbl commented 4 years ago

As mentioned in #272, this PR adds lazy loading capabilities to the function arrays. It will only source the functions that are requested in one of the prompts. I've done a quick spot check and it doesn't seem to cause any issues.

Cheers, Alex

jedahan commented 4 years ago

So I think the only downside of this, is if someone adds a function to either array that was supposed to be sourced first.

I think by understanding autoload/fpath we could have our cake and eat it too, but we might have to ask #zsh-users for help.

jedahan commented 4 years ago

I would love to have this feature, btw

alxbl commented 4 years ago

My understanding is that each function is self contained. If the plan is to have some sort of dependency management between functions then I agree that this approach won't work. I will read the manual for autoload and see if something can be done.

alxbl commented 4 years ago

Good news!

autoload works very nicely. It can even be used without touching fpath manually by specifying absolute paths. I've still got to test it with the existing plugin system, but initial tests show that

autoload -Uk /absolute/path/to/function_name will have the desired behavior of running the initialization code once upon first call and calling the function. The only caveat right now is that function files are suffixed with .zsh, and I think that this won't play nice with autoload (which expects file_name==function_name for the auto-call to work. I'll see if this can be modified, otherwise it might be necessary to follow autoload's syntax.

Cheers, Alex

jedahan commented 4 years ago

Thanks for the research and testing. I think it’s fine to rename the function files to not have a zsh extension.