From 0ac1a9c2f9bf3e929ecec510d34bbb3aa6f5ada0 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Wed, 31 Aug 2016 13:00:52 +1200 Subject: Use simpler method to find branch name Only one call to git(1), too; seems to work at least as far back as Git v1.5.6.5 --- bash/bashrc.d/prompt.bash | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) (limited to 'bash/bashrc.d') diff --git a/bash/bashrc.d/prompt.bash b/bash/bashrc.d/prompt.bash index 821afe25..e8429b26 100644 --- a/bash/bashrc.d/prompt.bash +++ b/bash/bashrc.d/prompt.bash @@ -101,16 +101,14 @@ prompt() { iswt=$(git rev-parse --is-inside-work-tree 2>/dev/null) [[ $iswt = true ]] || return - # Find a branch label, or a tag, or just show the short commit ID, - # in that order of preference; if none of that works, bail out. - local branch - branch=$( { - git symbolic-ref --quiet HEAD || - git describe --tags --exact-match HEAD || - git rev-parse --short HEAD - } 2>/dev/null ) - [[ -n $branch ]] || return - branch=${branch##*/} + # Find a local branch, remote branch, or tag (annotated or not), or + # failing all of that just show the short commit ID, in that order + # of preference; if none of that works, bail out + local name + name=$(git describe --all --always --exact-match \ + HEAD 2>/dev/null) || return + name=${name##*/} + [[ -n $name ]] || return # Refresh index so e.g. git-diff-files(1) is accurate git update-index --refresh >/dev/null @@ -161,7 +159,7 @@ prompt() { # Print the status in brackets; add a git: prefix only if there # might be another VCS prompt (because PROMPT_VCS is set) printf '(%s%s%s%s)' \ - "${PROMPT_VCS:+git:}" "${branch:-unknown}" \ + "${PROMPT_VCS:+git:}" "${name:-unknown}" \ "${proc:+:$proc}" "$state" ;; -- cgit v1.2.3