diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2016-08-31 13:00:52 +1200 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2016-08-31 13:00:52 +1200 |
commit | 0ac1a9c2f9bf3e929ecec510d34bbb3aa6f5ada0 (patch) | |
tree | fbe0cd921aa7174112eebd34ec9c2403e53981de /bash | |
parent | Use shorter "or" syntax within [[ ]] (diff) | |
download | dotfiles-0ac1a9c2f9bf3e929ecec510d34bbb3aa6f5ada0.tar.gz dotfiles-0ac1a9c2f9bf3e929ecec510d34bbb3aa6f5ada0.zip |
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
Diffstat (limited to 'bash')
-rw-r--r-- | bash/bashrc.d/prompt.bash | 20 |
1 files changed, 9 insertions, 11 deletions
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" ;; |