Last active
November 17, 2016 18:53
-
-
Save nilium/7440c8f53d28cb6d15ce to your computer and use it in GitHub Desktop.
Pipe all commit messages per-author through wc and such to get wordiness by user.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set_order () { | |
local oarg="$1" | |
case "$oarg" in | |
commits|c) | |
order=1 | |
;; | |
lines|l) | |
order=2 | |
;; | |
words|w) | |
order=3 | |
;; | |
bytes|b) | |
order=4 | |
;; | |
name|n) | |
order=5 | |
ordertype='-d' | |
;; | |
*) | |
printf "unrecognized ordering '%s'\n" "$oarg" 1>&2 | |
exit 1 | |
;; | |
esac | |
} | |
print_help () { | |
wrip -s -l=2 -i=0 -w="${COLUMNS:-80}" <<HELPTXT | |
git-wordiness [OPTIONS] | |
List general sums about commit messages (i.e., wc output). | |
OPTIONS | |
-csv | |
Output results in comma-separated value format. | |
-tsv | |
Output results in tab-separated value format. | |
-order=ORDER | |
Set the output ordering to one of the following: | |
- commits|c :: Order by total commits. | |
- lines|l :: Order by lines used in all commit messages (does not unbreak paragraphs). | |
- words|w :: Order by total words used in all commit messages. | |
- bytes|b :: Order by bytes used for all commit messages. | |
- name|n :: Order by committer name. | |
-r|-reverse | |
Reverse the output order. | |
HELPTXT | |
} | |
fmt='%10s %10s %10s %10s %s\n' | |
head=1 | |
order=1 | |
ordertype='-n' | |
reverse='cat' | |
sep=' ' | |
logargs=(--all) | |
while [[ $# -gt 0 ]] ; do | |
arg="$1" | |
shift | |
case "$arg" in | |
-h|-help|--help) | |
print_help 1>&2 | |
exit 0 | |
;; | |
-c|-csv|--csv) | |
fmt='%s,%s,%s,%s,%s\n' | |
sep=',' | |
;; | |
-t|-tsv|--tsv) | |
fmt='%s\t%s\t%s\t%s\t%s\n' | |
sep="$(printf '\t')" | |
;; | |
-order=*) set_order "${arg#-order=*}" ;; | |
--order=*) set_order "${arg#--order=*}" ;; | |
-o?) set_order "${arg:2}" ;; | |
-r|-reverse|--reverse) reverse='tail -r' ;; | |
-nh|-nohead|--nohead) head=0 ;; | |
--) | |
logargs=("$@") | |
break | |
;; | |
*) | |
logargs=("$arg" "$@") | |
break | |
;; | |
esac | |
done | |
logquote="$(if [[ "${#logargs[@]}" -gt 0 ]] ; then printf ' %q' "${logargs[@]}" ; fi)" | |
export fmt | |
if [[ $head == 1 ]] | |
then | |
printf "$fmt" COMMITS LINES WORDS BYTES NAME | |
fi | |
git log --pretty='%aN' "${logargs[@]}" | | |
sort | | |
uniq | | |
xargs -I @@ \ | |
env NAME=@@ \ | |
env REGEX='^@@ <' \ | |
bash -c 'printf "$fmt" $(git log '"$logquote"' --use-mailmap --pretty="%H" --author="$REGEX" | wc -l) $(git log '"$logquote"' --use-mailmap --pretty="%B" --author="$REGEX" | wc) "$NAME"' | \ | |
sort -b $ordertype -k "+${order}n" | | |
$reverse | |
# FIXME: Names with non-ASCII characters can throw-off alignment of columns. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment