From 2a109d30afe4ab164a946c307abc3d2a444a42ad Mon Sep 17 00:00:00 2001 From: Carlo Sala Date: Tue, 8 Oct 2024 20:26:23 +0200 Subject: [PATCH] feat(git): add escape hatch to enable async prompt --- README.md | 12 ++++++++++-- lib/git.zsh | 16 ++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 78db3a88f..1303292d2 100644 --- a/README.md +++ b/README.md @@ -48,7 +48,7 @@ Twitter), and join us on [Discord](https://discord.gg/ohmyzsh). - [Custom Plugins And Themes](#custom-plugins-and-themes) - [Enable GNU ls In macOS And freeBSD Systems](#enable-gnu-ls-in-macos-and-freebsd-systems) - [Skip Aliases](#skip-aliases) - - [Disable async git prompt](#disable-async-git-prompt) + - [Async git prompt](#async-git-prompt) - [Getting Updates](#getting-updates) - [Updates Verbosity](#updates-verbosity) - [Manual Updates](#manual-updates) @@ -415,7 +415,7 @@ zstyle ':omz:lib:directories' aliases no > It is also not currently aware of "aliases" that are defined as functions. Example of such are `gccd`, > `ggf`, or `ggl` functions from the git plugin. -### Disable async git prompt +### Async git prompt Async prompt functions are an experimental feature (included on April 3, 2024) that allows Oh My Zsh to render prompt information asynchronously. This can improve prompt rendering performance, but it might not work well @@ -426,6 +426,14 @@ turn it off by setting the following in your .zshrc file, before Oh My Zsh is so zstyle ':omz:alpha:lib:git' async-prompt no ``` +If your problem is that the git prompt just stopped appearing, you can try to force it setting the following +configuration before `oh-my-zsh.sh` is sourced. If it still does not work, please open an issue with your +case. + +```sh +zstyle ':omz:alpha:lib:git' async-prompt force +``` + ## Getting Updates By default, you will be prompted to check for updates every 2 weeks. You can choose other update modes by diff --git a/lib/git.zsh b/lib/git.zsh index 0efff3e07..a1b4d1587 100644 --- a/lib/git.zsh +++ b/lib/git.zsh @@ -44,6 +44,7 @@ function _omz_git_prompt_info() { # - https://github.com/ohmyzsh/ohmyzsh/issues/12331 # - https://github.com/ohmyzsh/ohmyzsh/issues/12360 # TODO(2024-06-12): @mcornella remove workaround when CentOS 7 reaches EOL +local _style if zstyle -t ':omz:alpha:lib:git' async-prompt \ || { is-at-least 5.0.6 && zstyle -T ':omz:alpha:lib:git' async-prompt }; then function git_prompt_info() { @@ -81,6 +82,21 @@ if zstyle -t ':omz:alpha:lib:git' async-prompt \ # Register the async handler first. This needs to be done before # the async request prompt is run precmd_functions=(_defer_async_git_register $precmd_functions) +elif zstyle -s ':omz:alpha:lib:git' async-prompt _style && [[ $_style == "force" ]]; then + function git_prompt_info() { + if [[ -n "${_OMZ_ASYNC_OUTPUT[_omz_git_prompt_info]}" ]]; then + echo -n "${_OMZ_ASYNC_OUTPUT[_omz_git_prompt_info]}" + fi + } + + function git_prompt_status() { + if [[ -n "${_OMZ_ASYNC_OUTPUT[_omz_git_prompt_status]}" ]]; then + echo -n "${_OMZ_ASYNC_OUTPUT[_omz_git_prompt_status]}" + fi + } + + _omz_register_handler _omz_git_prompt_info + _omz_register_handler _omz_git_prompt_status else function git_prompt_info() { _omz_git_prompt_info