feat(git): implement async completion for `git_prompt_status` (#12319)
This is important for themes using it, since it is usually a little slower than git_prompt_info.
Also two small fixes :
- the handler for git_prompt_info was incorrectly named _omz_git_prompt_status
- _defer_async_git_register was kept in precmd, there is no need to call it on each prompt
Diff
1diff --git a/lib/git.zsh b/lib/git.zsh
2index 4d6681c5b086a35162c4188936211c9b78265532..76b3778db571324525ced5540bd6d80f7c3b64c7 100644
3--- a/lib/git.zsh
4+++ b/lib/git.zsh
5@@ -9,7 +9,7 @@ function __git_prompt_git() {
6 GIT_OPTIONAL_LOCKS=0 command git "$@"
7 }
8 9-function _omz_git_prompt_status() {
10+function _omz_git_prompt_info() {
11 # If we are on a folder not tracked by git, get out.
12 # Otherwise, check for hide-info at global and local repository level
13 if ! __git_prompt_git rev-parse --git-dir &> /dev/null \
14@@ -40,6 +40,12 @@ function _omz_git_prompt_status() {
15 # Enable async prompt by default unless the setting is at false / no
16 if zstyle -T ':omz:alpha:lib:git' async-prompt; then
17 function git_prompt_info() {
18+ if [[ -n "$_OMZ_ASYNC_OUTPUT[_omz_git_prompt_info]" ]]; then
19+ echo -n "$_OMZ_ASYNC_OUTPUT[_omz_git_prompt_info]"
20+ fi
21+ }
22+
23+ function git_prompt_status() {
24 if [[ -n "$_OMZ_ASYNC_OUTPUT[_omz_git_prompt_status]" ]]; then
25 echo -n "$_OMZ_ASYNC_OUTPUT[_omz_git_prompt_status]"
26 fi
27@@ -51,8 +57,13 @@ if zstyle -T ':omz:alpha:lib:git' async-prompt; then
28 # Check if git_prompt_info is used in a prompt variable
29 case "${PS1}:${PS2}:${PS3}:${PS4}:${RPS1}:${RPS2}:${RPS3}:${RPS4}" in
30 *(\$\(git_prompt_info\)|\`git_prompt_info\`)*)
31+ _omz_register_handler _omz_git_prompt_info
32+ ;;
33+ esac
34+
35+ case "${PS1}:${PS2}:${PS3}:${PS4}:${RPS1}:${RPS2}:${RPS3}:${RPS4}" in
36+ *(\$\(git_prompt_status\)|\`git_prompt_status\`)*)
37 _omz_register_handler _omz_git_prompt_status
38- return
39 ;;
40 esac
4142@@ -65,6 +76,9 @@ if zstyle -T ':omz:alpha:lib:git' async-prompt; then
43 precmd_functions=(_defer_async_git_register $precmd_functions)
44 else
45 function git_prompt_info() {
46+ _omz_git_prompt_info
47+ }
48+ function git_prompt_status() {
49 _omz_git_prompt_status
50 }
51 fi
52@@ -197,7 +211,7 @@ function git_prompt_long_sha() {
53 SHA=$(__git_prompt_git rev-parse HEAD 2> /dev/null) && echo "$ZSH_THEME_GIT_PROMPT_SHA_BEFORE$SHA$ZSH_THEME_GIT_PROMPT_SHA_AFTER"
54 }
5556-function git_prompt_status() {
57+function _omz_git_prompt_status() {
58 [[ "$(__git_prompt_git config --get oh-my-zsh.hide-status 2>/dev/null)" = 1 ]] && return
5960 # Maps a git status prefix to an internal constant