From a00944c490c9e49ca842d5f509c7abe8c991beb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Pajot?= Date: Wed, 13 Mar 2013 18:31:26 +0100 Subject: [PATCH] Add some Mercurial informations : nb of lines inserted, deleted and nb of changes to commit --- liquidprompt | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/liquidprompt b/liquidprompt index 4557e67..5e72ac3 100755 --- a/liquidprompt +++ b/liquidprompt @@ -754,10 +754,37 @@ _lp_hg_branch_color() local ret branch=$(_lp_hg_branch) if [[ ! -z "$branch" ]] ; then - if [[ $(( $(hg status --quiet -n | wc -l) )) = 0 ]] ; then - ret="${LP_COLOR_UP}${branch}${NO_COL}" + + local has_untracked + has_untracked=$(hg status 2>/dev/null | grep '\(^\?\)' | wc -l) + if [[ -z "$has_untracked" ]] ; then + has_untracked="" else - ret="${LP_COLOR_CHANGES}${branch}${NO_COL}" # changes to commit + has_untracked="$LP_COLOR_CHANGES$LP_MARK_UNTRACKED" + fi + + local has_commit + has_commit=$(hg outgoing --no-merges ${branch} 2>/dev/null | grep '\(^changeset\:\)' | wc -l) + if [[ -z "$has_commit" ]] ; then + has_commit=0 + fi + + if [[ $(( $(hg status --quiet -n | wc -l) )) = 0 ]] ; then + if [[ "$has_commit" -gt "0" ]] ; then + # some commit(s) to push + ret="${LP_COLOR_COMMITS}${branch}${NO_COL}(${LP_COLOR_COMMITS}$has_commit${NO_COL})${has_untracked}${NO_COL}" + else + ret="${LP_COLOR_UP}${branch}${has_untracked}${NO_COL}" # nothing to commit or push + fi + else + local has_line + has_lines=$(hg diff --stat 2>/dev/null | tail -n 1 | awk 'FS=" " {printf("+%s/-%s\n", $4, $6)}') + if [[ "$has_commit" -gt "0" ]] ; then + # Changes to commit and commits to push + ret="${LP_COLOR_CHANGES}${branch}${NO_COL}(${LP_COLOR_DIFF}$has_lines${NO_COL},${LP_COLOR_COMMITS}$has_commit${NO_COL})${has_untracked}${NO_COL}" + else + ret="${LP_COLOR_CHANGES}${branch}${NO_COL}(${LP_COLOR_DIFF}$has_lines${NO_COL})${has_untracked}${NO_COL}" # changes to commit + fi fi echo -ne "$ret" fi