Compute lines of *unstaged* changes in prompt

Parse `git diff --shortstat` to get the line count of *unstaged* changes.

Improvements of the git related stuff are still possible, using more
plumbing commands, like:
* `git diff-index --quiet HEAD` to check for uncommitted changes (branch
  color), rather than relying on the `git diff --shortstat HEAD`
* `git ls-files --exclude-standard --others` to check for untracked
  files
This commit is contained in:
Alex 2013-12-11 17:20:52 +01:00 committed by Olivier Mengué
parent 3ff556a759
commit d2cb19fed8

View File

@ -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