From b2857a37747c3da40537e3b7fca7aac7fa15f2f7 Mon Sep 17 00:00:00 2001 From: Florian Baumann Date: Sun, 27 Mar 2011 20:44:17 +0200 Subject: [PATCH] added git_stats function to git plugin collection --- plugins/git.plugins.bash | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/plugins/git.plugins.bash b/plugins/git.plugins.bash index 5f4cc51..b0b9ce8 100644 --- a/plugins/git.plugins.bash +++ b/plugins/git.plugins.bash @@ -54,3 +54,42 @@ function git_info() { fi } +function git_stats { +# awesome work from https://github.com/esc/git-stats +# including some modifications + +if [ -n "$(git symbolic-ref HEAD 2> /dev/null)" ]; then + echo "Number of commits per author:" + git --no-pager shortlog -sn --all + AUTHORS=$( git shortlog -sn --all | cut -f2 | cut -f1 -d' ') + LOGOPTS="" + if [ "$1" == '-w' ]; then + LOGOPTS="$LOGOPTS -w" + shift + fi + if [ "$1" == '-M' ]; then + LOGOPTS="$LOGOPTS -M" + shift + fi + if [ "$1" == '-C' ]; then + LOGOPTS="$LOGOPTS -C --find-copies-harder" + shift + fi + for a in $AUTHORS + do + echo '-------------------' + echo "Statistics for: $a" + echo -n "Number of files changed: " + git log $LOGOPTS --all --numstat --format="%n" --author=$a | cut -f3 | sort -iu | wc -l + echo -n "Number of lines added: " + git log $LOGOPTS --all --numstat --format="%n" --author=$a | cut -f1 | awk '{s+=$1} END {print s}' + echo -n "Number of lines deleted: " + git log $LOGOPTS --all --numstat --format="%n" --author=$a | cut -f2 | awk '{s+=$1} END {print s}' + echo -n "Number of merges: " + git log $LOGOPTS --all --merges --author=$a | grep -c '^commit' + done +else + echo "you're currently not in a git repository" +fi +} + -- 2.17.1