diff --git a/bin/git-effort b/bin/git-effort index 8ada5a8..47524f1 100755 --- a/bin/git-effort +++ b/bin/git-effort @@ -9,7 +9,7 @@ color= # date() { - git log --pretty='format: %ai' $1 | cut -d ' ' -f 2 + git log --pretty='format: %ad' --date=short $1 } # @@ -36,10 +36,7 @@ show_cursor_and_cleanup() { # active_days() { - date $1 | uniq | awk ' - { sum += 1 } - END { print sum } - ' + uniq <(echo "$1") | wc -l } # @@ -62,12 +59,13 @@ color_for() { # effort() { - for file in "$@"; do - commits=`git log --oneline "$file" | wc -l` + file=$1 + local commit_dates=`date $file` + commits=`wc -l <<<"$(echo "$commit_dates")"` color='90' # ignore <= --above - test $commits -le $above && continue + test $commits -le $above && exit 0 # commits color_for $commits @@ -79,13 +77,13 @@ effort() { i=$(($i+1)) done - printf " \033[${color}m%s %-10d" $f_dot $commits + msg=$(printf " \033[${color}m%s %-10d" $f_dot $commits) # active days - active=`active_days "$file"` + active=`active_days "$commit_dates"` color_for $active - printf "\033[${color}m %d\033[0m\n" $active - done + msg="$msg $(printf "\033[${color}m %d\033[0m\n" $active)" + echo "$msg" } # @@ -106,7 +104,7 @@ sort_effort() { clear echo heading - cat $tmp | sort -rn -k 2 + < $tmp sort -rn -k 2 } # --above @@ -134,11 +132,18 @@ fi hide_cursor trap show_cursor_and_cleanup INT -# loop files +# export functions so subshells can call them +export -f effort +export -f color_for +export -f active_days +export -f date +export above heading +# send files to effort +printf "%s\0" "${files[@]}" | xargs -0 -n 1 -P 4 -I % bash -c "effort \"%\"" | tee $tmp -effort "${files[@]}" | tee $tmp +# if more than one file, sort and print test "$(wc -l $tmp | awk '{print $1}')" -gt 1 && sort_effort echo