Skip to content

Commit 9641b8e

Browse files
committed
Display remote branch name if we are on a remote branch commit
1 parent f3e13a4 commit 9641b8e

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

prompt.sh

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,16 @@ find_git_branch() {
1818
if tag=$(git describe --exact-match >&1 2> /dev/null); then
1919
branch="+$tag"
2020
else
21-
#branch='<detached>'
22-
# Or show the short hash
23-
branch='#'$(git rev-parse --short HEAD 2> /dev/null)
24-
# Or the long hash, with no leading '#'
25-
#branch=$(git rev-parse HEAD 2> /dev/null)
21+
# If it a remote branch, show that.
22+
branch=$(git name-rev --name-only HEAD | sed 's+^remotes/++')
23+
# But name-rev will also return if it is a few steps back from a remote branch, which sucks, so don't display that.
24+
if [[ "$branch" == "undefined" ]] || grep '\~' <<< "$branch" >/dev/null; then
25+
#branch='<detached>'
26+
# Or show the short hash
27+
branch='#'$(git rev-parse --short HEAD 2> /dev/null)
28+
# Or the long hash, with no leading '#'
29+
#branch=$(git rev-parse HEAD 2> /dev/null)
30+
fi
2631
fi
2732
else
2833
# This is a named branch. (It might be local or remote.)

0 commit comments

Comments
 (0)