tj.git-extras/bin/git-line-summary
spacewander b4a1fe0aa3 correct the broken regex
'*text' only matches string ended with 'text'. So it matches 'ASCII text',
but does not match 'ASCII text executable'. Before, `git summary
--line` just counts plain text file, now we fix it.
2015-04-24 23:13:16 +08:00

61 lines
884 B
Bash
Executable file

#!/usr/bin/env bash
project=${PWD##*/}
#
# list the last modified author for each line
#
function single_file {
while read data
do
if [[ $(file $data) = *text* ]]; then #
git blame --line-porcelain $data | sed -n 's/^author //p';
fi
done
}
#
# list the author for all file
#
function lines {
git ls-files | single_file
}
#
# count the line count
#
function count {
lines | wc -l
}
#
# sort by author modified lines
#
function authors {
lines | sort | uniq -c | sort -rn
}
#
# list as percentage for author modified lines
#
function result {
authors | awk '
{ args[NR] = $0; sum += $0 }
END {
printf " %-9s: %i\n", "lines", sum
printf " %-9s: \n", "authors"
for (i = 1; i <= NR; ++i) {
printf " %-30s %2.1f%%\n", args[i], 100 * args[i] / sum
}
}
'
}
# summary
echo
echo " project : $project"
result
echo