Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 20 additions & 15 deletions bin/git-effort
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ color=
#

date() {
git log --pretty='format: %ai' $1 | cut -d ' ' -f 2
git log --pretty='format: %ad' --date=short $1
}

#
Expand All @@ -36,10 +36,7 @@ show_cursor_and_cleanup() {
#

active_days() {
date $1 | uniq | awk '
{ sum += 1 }
END { print sum }
'
uniq <(echo "$1") | wc -l
}

#
Expand All @@ -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
Expand All @@ -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"
}

#
Expand All @@ -106,7 +104,7 @@ sort_effort() {
clear
echo
heading
cat $tmp | sort -rn -k 2
< $tmp sort -rn -k 2
}

# --above <n-commits>
Expand Down Expand Up @@ -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

Expand Down