From edb4cb1dced06a7b16e9e2682bc5bb34933ed30c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20Deparis?= Date: Sat, 1 Feb 2014 13:30:43 +0100 Subject: [PATCH 1/6] Replace over use of grep/cut with sed or awk, globally reduce number of fossil call --- liquidprompt | 70 ++++++++++------------------------------------------ 1 file changed, 13 insertions(+), 57 deletions(-) diff --git a/liquidprompt b/liquidprompt index 9788be4..4662cae 100755 --- a/liquidprompt +++ b/liquidprompt @@ -926,8 +926,8 @@ _lp_fossil_branch() { [[ "$LP_ENABLE_FOSSIL" != 1 ]] && return local branch - branch="$(fossil status 2>/dev/null | grep tags: | cut -c17-)" - if [[ -n "$branch" ]] ; then + branch=$(fossil status 2>/dev/null | sed -n "s/tags:[ ]*\(\w*\)$/\1/Ip") + if [ -n "$branch" ]; then _lp_escape "$branch" else if fossil info &>/dev/null ; then @@ -951,76 +951,32 @@ _lp_fossil_branch_color() local branch branch="$(_lp_fossil_branch)" - if [[ -n "$branch" ]] ; then + if [ -n "$branch" ]; then local C2E # Modified files (added or edited) - local C2D # Deleted files local C2A # Extras files - local C2AA # Added files - local PLUSLINE # Added lines - local MINUSLINE # Deleted lines local ret C2E=$(fossil changes | wc -l) C2A=$(fossil extras | wc -l) - PLUSLINE=$(fossil diff | egrep -c '^\+[^+].+$') - MINUSLINE=$(fossil diff | egrep -c '^-[^-].+$') - ret="" + ret=$(fossil diff -v | awk "/^(+[^+])|(+$)/ { plus+=1; } /^(-[^-])|(-$)/ { minus+=1; } END { total=\"\"; if(plus>0){ total=\"+\"plus; if(minus>0) total=total\"/\"; } if(minus>0) total=total\"-\"minus; print total;}") - C2AA=$(fossil changes | grep -c "ADDED") - if [[ $C2AA -gt 0 ]] ; then - # We count the line "à la" git - local ADDFILE - local FILE - ADDFILE=$(fossil changes | grep ADDED | sed -e 's/\s\{2,\}/ /g' | cut -d" " -f2) - for FILE in $ADDFILE ; do - PLULI=$(wc -l < $FILE) - let PLUSLINE=$PLUSLINE+$PLULI - done + if [ "$C2E" -gt 0 ]; then + if [ -n "$ret" ]; then + ret+=" in " + fi + ret="(${LP_COLOR_DIFF}${ret}${C2E}${NO_COL})" fi - if [[ $PLUSLINE -gt 0 ]] ; then - ret+="+$PLUSLINE" - fi - - C2D=$(fossil changes | grep -c "DELETED") - if [[ $C2D -gt 0 ]] ; then - # We count the line "à la" git - local DELFILE - local FILE - DELFILE=$(fossil changes | grep DELETED | sed -e 's/\s\{2,\}/ /g' | cut -d" " -f2) - for FILE in $DELFILE ; do - MINLI=$(wc -l < $FILE) - let MINUSLINE=$MINUSLINE+$MINLI - done - fi - - if [[ $MINUSLINE -gt 0 ]] ; then - if [[ "$ret" = "" ]] ; then - ret+="-$MINUSLINE" - else - ret+="/-$MINUSLINE" - fi - fi - - if [[ "$C2E" -gt 0 ]] ; then - ret+=" in $C2E" - fi - - if [[ "$C2A" -gt 0 ]] ; then + if [ "$C2A" -gt 0 ]; then C2A="$LP_MARK_UNTRACKED" else C2A="" fi - if [[ "$ret" != "" ]] ; then - ret="(${LP_COLOR_DIFF}$ret${NO_COL})" - fi - - - if [[ "$branch" = "no-tag" ]] ; then + if [ "$branch" = "no-tag" ]; then # Warning, your branch has no tag name ! branch="${LP_COLOR_COMMITS}$branch${NO_COL}$ret${LP_COLOR_COMMITS}$C2A${NO_COL}" else - if [[ "$C2E" -eq 0 && "$C2D" -eq 0 ]] ; then + if [ "$C2E" -eq 0 ]; then # All is up-to-date branch="${LP_COLOR_UP}$branch$C2A${NO_COL}" else @@ -1028,7 +984,7 @@ _lp_fossil_branch_color() branch="${LP_COLOR_CHANGES}$branch${NO_COL}$ret${LP_COLOR_CHANGES}$C2A${NO_COL}" fi fi - _lp_escape "$branch" + echo "$branch" fi } From e2b3ad6313a0d2701a5a011260f64f95e3ba9b8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20Deparis?= Date: Sat, 1 Feb 2014 13:45:23 +0100 Subject: [PATCH 2/6] Forgot one _lp_escape --- liquidprompt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/liquidprompt b/liquidprompt index 4662cae..43560c1 100755 --- a/liquidprompt +++ b/liquidprompt @@ -928,7 +928,7 @@ _lp_fossil_branch() local branch branch=$(fossil status 2>/dev/null | sed -n "s/tags:[ ]*\(\w*\)$/\1/Ip") if [ -n "$branch" ]; then - _lp_escape "$branch" + echo "$branch" else if fossil info &>/dev/null ; then echo "no-tag" From 9f0c0e6d47f11f410caaea3ac0045a86f3b612b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20Deparis?= Date: Sat, 1 Feb 2014 15:52:13 +0100 Subject: [PATCH 3/6] Fossil MARK_UNTRACKED is now colorized as for git or hg support --- liquidprompt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/liquidprompt b/liquidprompt index 43560c1..5b95ae9 100755 --- a/liquidprompt +++ b/liquidprompt @@ -967,7 +967,7 @@ _lp_fossil_branch_color() fi if [ "$C2A" -gt 0 ]; then - C2A="$LP_MARK_UNTRACKED" + C2A="$LP_COLOR_CHANGES$LP_MARK_UNTRACKED" else C2A="" fi From f48f56ab303f5a5179ffa3036c7c8bd4bc8b97a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Mengu=C3=A9?= Date: Fri, 14 Feb 2014 18:28:54 +0100 Subject: [PATCH 4/6] Fossil support: more cleanup --- liquidprompt | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/liquidprompt b/liquidprompt index 5b95ae9..e12444c 100755 --- a/liquidprompt +++ b/liquidprompt @@ -952,31 +952,29 @@ _lp_fossil_branch_color() branch="$(_lp_fossil_branch)" if [ -n "$branch" ]; then - local C2E # Modified files (added or edited) + local -i C2E # Modified files (added or edited) local C2A # Extras files local ret C2E=$(fossil changes | wc -l) C2A=$(fossil extras | wc -l) ret=$(fossil diff -v | awk "/^(+[^+])|(+$)/ { plus+=1; } /^(-[^-])|(-$)/ { minus+=1; } END { total=\"\"; if(plus>0){ total=\"+\"plus; if(minus>0) total=total\"/\"; } if(minus>0) total=total\"-\"minus; print total;}") - if [ "$C2E" -gt 0 ]; then - if [ -n "$ret" ]; then - ret+=" in " - fi + if (( C2E > 0 )); then + [[ -n "$ret" ]] && ret+=" in " ret="(${LP_COLOR_DIFF}${ret}${C2E}${NO_COL})" fi - if [ "$C2A" -gt 0 ]; then + if (( $C2A > 0 )); then C2A="$LP_COLOR_CHANGES$LP_MARK_UNTRACKED" else C2A="" fi - if [ "$branch" = "no-tag" ]; then + if [[ "$branch" = "no-tag" ]]; then # Warning, your branch has no tag name ! branch="${LP_COLOR_COMMITS}$branch${NO_COL}$ret${LP_COLOR_COMMITS}$C2A${NO_COL}" else - if [ "$C2E" -eq 0 ]; then + if (( C2E == 0 )); then # All is up-to-date branch="${LP_COLOR_UP}$branch$C2A${NO_COL}" else From f24a41d9116b750d671f0a03172ee587f8250bc8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Mengu=C3=A9?= Date: Thu, 20 Feb 2014 21:09:42 +0100 Subject: [PATCH 5/6] Fix tabs --- liquidprompt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/liquidprompt b/liquidprompt index e12444c..f14d248 100755 --- a/liquidprompt +++ b/liquidprompt @@ -957,11 +957,11 @@ _lp_fossil_branch_color() local ret C2E=$(fossil changes | wc -l) C2A=$(fossil extras | wc -l) - ret=$(fossil diff -v | awk "/^(+[^+])|(+$)/ { plus+=1; } /^(-[^-])|(-$)/ { minus+=1; } END { total=\"\"; if(plus>0){ total=\"+\"plus; if(minus>0) total=total\"/\"; } if(minus>0) total=total\"-\"minus; print total;}") + ret=$(fossil diff -v | awk "/^(+[^+])|(+$)/ { plus+=1; } /^(-[^-])|(-$)/ { minus+=1; } END { total=\"\"; if(plus>0){ total=\"+\"plus; if(minus>0) total=total\"/\"; } if(minus>0) total=total\"-\"minus; print total;}") if (( C2E > 0 )); then - [[ -n "$ret" ]] && ret+=" in " - ret="(${LP_COLOR_DIFF}${ret}${C2E}${NO_COL})" + [[ -n "$ret" ]] && ret+=" in " + ret="(${LP_COLOR_DIFF}${ret}${C2E}${NO_COL})" fi if (( $C2A > 0 )); then From c71abe49a5a5cf0d6d066ddbce3da62e830360cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Mengu=C3=A9?= Date: Thu, 20 Feb 2014 21:35:57 +0100 Subject: [PATCH 6/6] Fossil: use internal diff (fossil diff -i) Thanks to @sekiroh for the tip... --- liquidprompt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/liquidprompt b/liquidprompt index f14d248..568576a 100755 --- a/liquidprompt +++ b/liquidprompt @@ -957,7 +957,7 @@ _lp_fossil_branch_color() local ret C2E=$(fossil changes | wc -l) C2A=$(fossil extras | wc -l) - ret=$(fossil diff -v | awk "/^(+[^+])|(+$)/ { plus+=1; } /^(-[^-])|(-$)/ { minus+=1; } END { total=\"\"; if(plus>0){ total=\"+\"plus; if(minus>0) total=total\"/\"; } if(minus>0) total=total\"-\"minus; print total;}") + ret=$(fossil diff -i -v | awk "/^(+[^+])|(+$)/ { plus+=1; } /^(-[^-])|(-$)/ { minus+=1; } END { total=\"\"; if(plus>0){ total=\"+\"plus; if(minus>0) total=total\"/\"; } if(minus>0) total=total\"-\"minus; print total;}") if (( C2E > 0 )); then [[ -n "$ret" ]] && ret+=" in "