diff --git a/lib/git.zsh b/lib/git.zsh index 069fadda7..ac266b8ae 100644 --- a/lib/git.zsh +++ b/lib/git.zsh @@ -53,17 +53,26 @@ # get the name of the branch we are on function git_prompt_info() { + local branch [[ GIT_HIDE == 'true' ]] && return - ref=$(command git symbolic-ref HEAD 2> /dev/null) || \ - ref=$(command git rev-parse --short HEAD 2> /dev/null) || return + branch=$(current_branch) || return 1 printf '%s%s%s%s\n' \ $ZSH_THEME_GIT_PROMPT_PREFIX \ - ${ref#refs/heads/} \ + $branch \ $(parse_git_dirty) \ $ZSH_THEME_GIT_PROMPT_SUFFIX } +# Shows the current git branch. +# Exits with 1 when git is not available +git_current_branch() { + local ref + ref=$(command git symbolic-ref HEAD 2>/dev/null) || \ + ref=$(command git rev-parse --short HEAD 2>/dev/null) || return 1 + echo ${ref#refs/heads/} +} + # Checks if working tree is dirty parse_git_dirty() { [[ GIT_HIDE == 'true' ]] && return