diff options
author | Tuowen Zhao <ztuowen@gmail.com> | 2020-12-16 22:13:45 -0700 |
---|---|---|
committer | Tuowen Zhao <ztuowen@gmail.com> | 2020-12-16 22:13:45 -0700 |
commit | fb45741fc1dbd40dd2be72bc35a28c6ee8f3f7a5 (patch) | |
tree | dd7746c9910755dfeb5bf28bda68e28b47d5771f /lib/git.zsh | |
parent | 3aaa0bc62ece494dd2b6e47a191de79e562156f9 (diff) | |
parent | b28665aebb4c1b07a57890eb59551bc51d0acf37 (diff) | |
download | zsh-fb45741fc1dbd40dd2be72bc35a28c6ee8f3f7a5.tar.gz zsh-fb45741fc1dbd40dd2be72bc35a28c6ee8f3f7a5.tar.bz2 zsh-fb45741fc1dbd40dd2be72bc35a28c6ee8f3f7a5.zip |
Merge remote-tracking branch 'origin/master'
Diffstat (limited to 'lib/git.zsh')
-rw-r--r-- | lib/git.zsh | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/lib/git.zsh b/lib/git.zsh index 53d39609e..157c85062 100644 --- a/lib/git.zsh +++ b/lib/git.zsh @@ -9,14 +9,27 @@ function __git_prompt_git() { GIT_OPTIONAL_LOCKS=0 command git "$@" } -# Outputs current branch info in prompt format function git_prompt_info() { + # 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 + return 0 + fi + local ref - if [[ "$(__git_prompt_git config --get oh-my-zsh.hide-status 2>/dev/null)" != "1" ]]; then - ref=$(__git_prompt_git symbolic-ref HEAD 2> /dev/null) || \ - ref=$(__git_prompt_git rev-parse --short HEAD 2> /dev/null) || return 0 - echo "$ZSH_THEME_GIT_PROMPT_PREFIX${ref#refs/heads/}$(parse_git_dirty)$ZSH_THEME_GIT_PROMPT_SUFFIX" + ref=$(__git_prompt_git symbolic-ref --short HEAD 2> /dev/null) \ + || ref=$(__git_prompt_git rev-parse --short HEAD 2> /dev/null) \ + || return 0 + + # Use global ZSH_THEME_GIT_SHOW_UPSTREAM=1 for including upstream remote info + local upstream + if (( ${+ZSH_THEME_GIT_SHOW_UPSTREAM} )); then + upstream=$(__git_prompt_git rev-parse --abbrev-ref --symbolic-full-name "@{upstream}" 2>/dev/null) \ + && upstream=" -> ${upstream}" fi + + echo "${ZSH_THEME_GIT_PROMPT_PREFIX}${ref}${upstream}$(parse_git_dirty)${ZSH_THEME_GIT_PROMPT_SUFFIX}" } # Checks if working tree is dirty |