From a75f6db5bcfca582b2d30fc0ef534aaf0445f71f Mon Sep 17 00:00:00 2001 From: Tj Holowaychuk Date: Wed, 8 Feb 2012 16:31:17 -0800 Subject: [PATCH] refactord git-effort(1) --- bin/git-effort | 49 +++++++++++++++++++++++++++++++++---------------- 1 file changed, 33 insertions(+), 16 deletions(-) diff --git a/bin/git-effort b/bin/git-effort index 77605f8..fd05c85 100755 --- a/bin/git-effort +++ b/bin/git-effort @@ -2,11 +2,20 @@ files=`git ls-files` above='0' +color= + +# +# get date for the given +# date() { git log --pretty='format: %ai' $1 | cut -d ' ' -f 2 } +# +# get active days for the given +# + active_days() { date $1 | uniq | awk ' { sum += 1 } @@ -14,33 +23,41 @@ active_days() { ' } -if test "$1" = "--above"; then - above=$2 -fi +# +# set 'color' based on the given +# + +color_for() { + test $1 -gt 10 && color='33' + test $1 -gt 25 && color='33;1' + test $1 -gt 50 && color='93' + test $1 -gt 75 && color='93;1' + test $1 -gt 100 && color='31' + test $1 -gt 125 && color='31;1' + test $1 -gt 150 && color='91' + test $1 -gt 200 && color='91;1' +} + +# --above + +test "$1" = "--above" && above=$2 + +# heading echo printf " %-45s %-10s %s\n" 'file' 'commits' 'active days' echo +# loop files + for file in $files; do commits=`git log --oneline $file | wc -l` color='90' - if test $commits -le $above; then - continue - fi + test $commits -le $above && continue active=`active_days $file` - - test $commits -gt 10 && color='33' - test $commits -gt 25 && color='33;1' - test $commits -gt 50 && color='93' - test $commits -gt 75 && color='93;1' - test $commits -gt 100 && color='31' - test $commits -gt 125 && color='31;1' - test $commits -gt 150 && color='91' - test $commits -gt 200 && color='91;1' - + color_for $commits printf " \033[${color}m%-45s %-10d %d\033[0m\n" $file $commits $active done echo