From e72f359a313366d5d7795742aa7dc7bd6503f4a8 Mon Sep 17 00:00:00 2001 From: LFDM <1986gh@gmail.com> Date: Tue, 7 Jan 2014 08:50:44 +0100 Subject: [PATCH] Extracts git_current_branch --- lib/git.zsh | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) 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