Skip to content

Commit

Permalink
Display remote branch name if we are on a remote branch commit
Browse files Browse the repository at this point in the history
  • Loading branch information
joeytwiddle committed Mar 11, 2020
1 parent f3e13a4 commit 9641b8e
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions prompt.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,16 @@ find_git_branch() {
if tag=$(git describe --exact-match >&1 2> /dev/null); then
branch="+$tag"
else
#branch='<detached>'
# 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='<detached>'
# 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.)
Expand Down

0 comments on commit 9641b8e

Please sign in to comment.