mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2026-06-16 11:36:16 +08:00
feat(git): show default branch in prompt
This commit is contained in:
parent
70ad5e3df8
commit
d453551712
33
lib/git.zsh
33
lib/git.zsh
@ -29,14 +29,35 @@ function _omz_git_prompt_info() {
|
||||
|| 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}"
|
||||
local upstream upstream_ref
|
||||
if (( ${+ZSH_THEME_GIT_SHOW_UPSTREAM} || ${+ZSH_THEME_GIT_SHOW_DEFAULT_BRANCH} )); then
|
||||
upstream_ref=$(__git_prompt_git rev-parse --abbrev-ref --symbolic-full-name "@{upstream}" 2>/dev/null) || upstream_ref=
|
||||
fi
|
||||
|
||||
echo "${ZSH_THEME_GIT_PROMPT_PREFIX}${ref//\%/%%}${upstream//\%/%%}$(parse_git_dirty)${ZSH_THEME_GIT_PROMPT_SUFFIX}"
|
||||
# Use global ZSH_THEME_GIT_SHOW_UPSTREAM=1 for including upstream remote info
|
||||
if (( ${+ZSH_THEME_GIT_SHOW_UPSTREAM} )) && [[ -n "$upstream_ref" ]]; then
|
||||
upstream=" -> ${upstream_ref}"
|
||||
fi
|
||||
|
||||
# Use global ZSH_THEME_GIT_SHOW_DEFAULT_BRANCH=1 for including the repository's
|
||||
# default branch, as reported by the upstream remote's HEAD, falling back to
|
||||
# origin/HEAD. By default this only displays when it differs from the current
|
||||
# branch. Set it to "always" to display it even when both branches are the same.
|
||||
local default_branch default_branch_remote
|
||||
if (( ${+ZSH_THEME_GIT_SHOW_DEFAULT_BRANCH} )); then
|
||||
default_branch_remote="${upstream_ref%%/*}"
|
||||
default_branch_remote="${default_branch_remote:-origin}"
|
||||
default_branch=$(__git_prompt_git symbolic-ref --quiet --short "refs/remotes/${default_branch_remote}/HEAD" 2>/dev/null) || default_branch=
|
||||
default_branch=${default_branch#${default_branch_remote}/}
|
||||
if [[ -n "$default_branch" \
|
||||
&& ( "$ZSH_THEME_GIT_SHOW_DEFAULT_BRANCH" = always || "$default_branch" != "$ref" ) ]]; then
|
||||
default_branch="${ZSH_THEME_GIT_PROMPT_DEFAULT_BRANCH_PREFIX:-" | default: "}${default_branch}${ZSH_THEME_GIT_PROMPT_DEFAULT_BRANCH_SUFFIX}"
|
||||
else
|
||||
default_branch=
|
||||
fi
|
||||
fi
|
||||
|
||||
echo "${ZSH_THEME_GIT_PROMPT_PREFIX}${ref//\%/%%}${upstream//\%/%%}${default_branch//\%/%%}$(parse_git_dirty)${ZSH_THEME_GIT_PROMPT_SUFFIX}"
|
||||
}
|
||||
|
||||
function _omz_git_prompt_status() {
|
||||
|
||||
@ -9,6 +9,10 @@ ZSH_THEME_GIT_PROMPT_PREFIX="git:(" # Beginning of the git prompt, before the
|
||||
ZSH_THEME_GIT_PROMPT_SUFFIX=")" # End of the git prompt
|
||||
ZSH_THEME_GIT_PROMPT_DIRTY="*" # Text to display if the branch is dirty
|
||||
ZSH_THEME_GIT_PROMPT_CLEAN="" # Text to display if the branch is clean
|
||||
# ZSH_THEME_GIT_SHOW_DEFAULT_BRANCH=1 # Set to 1 to show the default branch when different from current
|
||||
# ZSH_THEME_GIT_SHOW_DEFAULT_BRANCH=always # Set to "always" to show it even when equal to current
|
||||
# ZSH_THEME_GIT_PROMPT_DEFAULT_BRANCH_PREFIX=" | default: " # Text before the default branch
|
||||
# ZSH_THEME_GIT_PROMPT_DEFAULT_BRANCH_SUFFIX="" # Text after the default branch
|
||||
ZSH_THEME_RUBY_PROMPT_PREFIX="("
|
||||
ZSH_THEME_RUBY_PROMPT_SUFFIX=")"
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user