mirror of
https://github.com/tj/git-extras.git
synced 2026-09-10 15:36:21 -04:00
1. Fix print format with special characters 2. Fix Fatal when exist special characters in git blame output 3. Fix raise error when exist not committed new files
61 lines
905 B
Bash
Executable file
61 lines
905 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 2>/dev/null | grep "author\ " | 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 {
|
|
for (i = 1; i <= NR; ++i) {
|
|
printf " %s, %2.1f%%\n", args[i], 100 * args[i] / sum
|
|
}
|
|
}
|
|
' | column -t -s,
|
|
}
|
|
|
|
# summary
|
|
|
|
echo
|
|
echo " project : $project"
|
|
echo " lines :" $(count)
|
|
echo " authors :"
|
|
result
|
|
echo
|
|
|