From d2cb19fed880f6b034880d0a2240eb901e9380d4 Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 11 Dec 2013 17:20:52 +0100 Subject: [PATCH] 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 --- liquidprompt | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) 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