ohmyzsh/ohmyzsh

lib/git depends on lib/async_prompt but does not source it

ctrueden opened this issue · 3 comments

Describe the bug

I use Oh My Zsh via the zpm plugin manager. After a recent update, I started seeing the following error upon every new shell:

_defer_async_git_register:4: command not found: _omz_register_handler

The reason is that the function _defer_async_git_register in lib/git.zsh invokes _omz_register_handler, which is defined in lib/async_prompt.zsh, but I was not including async_prompt in my list of libraries to load.

To fix, I simply added async_prompt.zsh to my library list (ctrueden/dotfiles@5a51526).

I'm wondering: is it expected that all files in lib must be sourced? According to this wiki page, ohmyzsh "Discovers and sources all lib files, in alphabetical order, respecting custom overrides" during initialization. If so, I can change my zshrc to do the same, always loading all files in the lib folder, and we can close this issue as invalid. But I thought I'd double check, since this is the first time I've had issues with cherry-picking only the libs I want, and if such implicit dependencies between libs are unintended, then I guess this should be fixed somehow.

Steps to reproduce

Here is a simple .zshrc to reproduce the issue:

if [[ ! -f ~/.zpm/zpm.zsh ]]; then
	git clone --recursive https://github.com/zpm-zsh/zpm ~/.zpm
fi
source ~/.zpm/zpm.zsh
zpm load @omz
omz_libs=(
#	@omz/lib/async_prompt       # uncomment this line to avoid the error message
	@omz/lib/git               # git-related utility functions
)
zpm load $omz_libs

zsh_plugins=(
	@omz/git                   # git aliases and improved completion
)
zpm load $zsh_plugins

It might be necessary to enable a theme that includes the git prompt; I'm not sure.

(NB: I stripped this down from my dotfiles, and did not test the stripped down version, but hopefully it's not necessary to reproduce this issue, since it's very simple to understand).

Expected behavior

Shell should initialize without the error message.

Screenshots and recordings

No response

OS / Linux distribution

Ubuntu 20.04.5 LTS, Ubuntu 23.10

Zsh version

5.8, 5.9

Oh My Zsh version

master (9d529c4)

Terminal emulator

Guake Terminal 3.10

If using WSL on Windows, which version of WSL

None

Additional context

No response

I'm guessing this is why the check_git_prompt_info function is causing (detached-head) in my theme... (because git_prompt_info returns an empty string)

Looks like there's a readme update regarding it/how to disable async git prompt for those who just want things to work and don't want to tinker: https://github.com/ohmyzsh/ohmyzsh#disable-async-git-prompt

So here's a short term and a mid term answer.

In the short term, there are no current guarantees whether a lib file is or isn't supposed to be loaded. For now, there is a hodge podge of logic within each lib file, and it is a possibility that a lib file requires one of the previous ones (sorted alphabetically). If you have a custom setup, where only some lib files are sourced, some functionality will be broken if there are lib file changes such as the one you encountered.

We realise that many people use plugin managers, or have custom files to override lib files. Some of the appeal of this is that some lib files have side effects or add performance overhead on startup.

That's why, in the mid term, we are thinking of separating required logic (in essence, a folder of loadable functions, maybe via autoload) so that all Oh My Zsh users load them on startup as required, including this automatically out of the box on plugin managers. The contract on those functions / APIs would be that they don't have a performance impact, and they don't have side effects. This will improve the integration with plugin managers.

But, for now, the async_prompt lib file is indeed required.