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.)