#!/bin/bash
# Usage: git-who-owns-this [-w] FILE
#
# Report `git blame`-based stats listing the number of lines in a file by each author.
# Add `-w` to ignore whitespace changes.
#
# From an example in the git-blame manpage.

git_who_owns_this () {
    local w=
    if [[ $1 == -w ]]; then  # flag for ignoring whitespace
        w=-w
        shift
    fi
    local file="${1?Need file}"
    git blame "$w" --line-porcelain "$file" |
        sed -n 's/^author //p' |
        sort | uniq -c | sort -rnb
}

git_who_owns_this "${@}"

