diff options
| author | Marc Cornellà <marc@mcornella.com> | 2024-03-07 14:39:05 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-03-07 14:39:05 +0100 |
| commit | 083cc2c8e8742bab8cce8c73a3e96f398e6b2da7 (patch) | |
| tree | 5d411bb0daef444dcaf36fa7763ee40922d4c43a /lib/git.zsh | |
| parent | 4fca7ccb55eb4904f515806ffca51d27ee1cc670 (diff) | |
| download | zsh-083cc2c8e8742bab8cce8c73a3e96f398e6b2da7.tar.gz zsh-083cc2c8e8742bab8cce8c73a3e96f398e6b2da7.tar.bz2 zsh-083cc2c8e8742bab8cce8c73a3e96f398e6b2da7.zip | |
feat(async)!: implement async prompt API and apply to git prompt (#12257)
BREAKING CHANGE: the `git_prompt_info` prompt function has been
reworked by default to use the new async prompt feature. If you're
experiencing issues see #12257.
Co-authored-by: Carlo Sala <carlosalag@protonmail.com>
Diffstat (limited to 'lib/git.zsh')
| -rw-r--r-- | lib/git.zsh | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/lib/git.zsh b/lib/git.zsh index f049f73c2..6f4823458 100644 --- a/lib/git.zsh +++ b/lib/git.zsh @@ -9,14 +9,18 @@ function __git_prompt_git() { GIT_OPTIONAL_LOCKS=0 command git "$@" } -function git_prompt_info() { +function _omz_git_prompt_status() { # If we are on a folder not tracked by git, get out. # Otherwise, check for hide-info at global and local repository level if ! __git_prompt_git rev-parse --git-dir &> /dev/null \ - || [[ "$(__git_prompt_git config --get oh-my-zsh.hide-info 2>/dev/null)" == 1 ]]; then + || [[ "$(__git_prompt_git config --get oh-my-zsh.hide-info 2>/dev/null)" == 1 ]]; then return 0 fi + # Get either: + # - the current branch name + # - the tag name if we are on a tag + # - the short SHA of the current commit local ref ref=$(__git_prompt_git symbolic-ref --short HEAD 2> /dev/null) \ || ref=$(__git_prompt_git describe --tags --exact-match HEAD 2> /dev/null) \ @@ -33,6 +37,20 @@ function git_prompt_info() { echo "${ZSH_THEME_GIT_PROMPT_PREFIX}${ref:gs/%/%%}${upstream:gs/%/%%}$(parse_git_dirty)${ZSH_THEME_GIT_PROMPT_SUFFIX}" } +# Enable async prompt by default unless the setting is at false / no +if zstyle -T ':omz:alpha:lib:git' async-prompt; then + function git_prompt_info() { + _omz_register_handler _omz_git_prompt_status + if [[ -n "$_OMZ_ASYNC_OUTPUT[_omz_git_prompt_status]" ]]; then + echo -n "$_OMZ_ASYNC_OUTPUT[_omz_git_prompt_status]" + fi + } +else + function git_prompt_info() { + _omz_git_prompt_status + } +fi + # Checks if working tree is dirty function parse_git_dirty() { local STATUS |
