diff --git a/liquidprompt b/liquidprompt index 8cd1785..bb771fe 100755 --- a/liquidprompt +++ b/liquidprompt @@ -773,16 +773,32 @@ _lp_git_branch_color() fi fi - local shortstat local ret + local shortstat # only to check for uncommitted changes shortstat="$(LC_ALL=C \git diff --shortstat HEAD 2>/dev/null)" + if [[ -n "$shortstat" ]] ; then + local u_stat # shorstat of *unstaged* changes + u_stat="$(LC_ALL=C \git diff --shortstat 2>/dev/null)" + u_stat=${u_stat/*changed, /} # removing "n file(s) changed" + + local i_lines # inserted lines + if [[ "$u_stat" = *insertion* ]] ; then + i_lines=${u_stat/ inser*} + else + i_lines=0 + fi + + local d_lines # deleted lines + if [[ "$u_stat" = *deletion* ]] ; then + d_lines=${u_stat/*\(+\), } + d_lines=${d_lines/ del*/} + else + d_lines=0 + fi + local has_lines - #has_lines=$(\git diff --numstat 2>/dev/null | awk 'NF==3 {plus+=$1; minus+=$2} END {printf("+%d/-%d\n", plus, minus)}') - has_lines=${shortstat/*changed, /} - has_lines=${has_lines/ inser*, /\/-} - has_lines=${has_lines/ del*/} - [[ "$shortstat" = *insertion* ]] && has_lines="+${has_lines/ inser*/}" || has_lines="-$has_lines" + has_lines="+$i_lines/-$d_lines" if [[ "$has_commit" -gt "0" ]] ; then # Changes to commit and commits to push