From 9641b8eae436c9839f0b56994d72903f2b2de0b6 Mon Sep 17 00:00:00 2001 From: Paul Joey Clark Date: Wed, 11 Mar 2020 16:06:55 +0800 Subject: [PATCH] Display remote branch name if we are on a remote branch commit --- prompt.sh | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/prompt.sh b/prompt.sh index 0477672..6d27f12 100644 --- a/prompt.sh +++ b/prompt.sh @@ -18,11 +18,16 @@ find_git_branch() { if tag=$(git describe --exact-match >&1 2> /dev/null); then branch="+$tag" else - #branch='' - # Or show the short hash - branch='#'$(git rev-parse --short HEAD 2> /dev/null) - # Or the long hash, with no leading '#' - #branch=$(git rev-parse HEAD 2> /dev/null) + # If it a remote branch, show that. + branch=$(git name-rev --name-only HEAD | sed 's+^remotes/++') + # But name-rev will also return if it is a few steps back from a remote branch, which sucks, so don't display that. + if [[ "$branch" == "undefined" ]] || grep '\~' <<< "$branch" >/dev/null; then + #branch='' + # Or show the short hash + branch='#'$(git rev-parse --short HEAD 2> /dev/null) + # Or the long hash, with no leading '#' + #branch=$(git rev-parse HEAD 2> /dev/null) + fi fi else # This is a named branch. (It might be local or remote.)