fix prompt_ps1_git_branch when non-active branches are ahead/behind

This commit is contained in:
Josh Holtrop 2016-06-29 15:06:00 -04:00
parent 7e6284740e
commit d3b8edfaca

View File

@ -25,11 +25,12 @@ function prompt_ps1_git_branch()
while read -r git_branch_out_line; do while read -r git_branch_out_line; do
if [[ "$git_branch_out_line" =~ $re ]]; then if [[ "$git_branch_out_line" =~ $re ]]; then
local current_branch="${BASH_REMATCH[2]:-${BASH_REMATCH[3]}}" local current_branch="${BASH_REMATCH[2]:-${BASH_REMATCH[3]}}"
re="((ahead|behind)[^]]*)\\]" local re2="((ahead|behind)[^]]*)\\]"
if [[ "$git_branch_out" =~ $re ]]; then if [[ "$git_branch_out_line" =~ $re2 ]]; then
current_branch="$current_branch: ${BASH_REMATCH[1]}" current_branch="$current_branch: ${BASH_REMATCH[1]}"
fi fi
echo " [${current_branch}${ahead_behind}]" echo " [${current_branch}${ahead_behind}]"
break
fi fi
done <<< "$git_branch_out" done <<< "$git_branch_out"
fi fi