summaryrefslogtreecommitdiff
path: root/lib/git.zsh
diff options
context:
space:
mode:
Diffstat (limited to 'lib/git.zsh')
-rw-r--r--lib/git.zsh22
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