Skip to content

Instantly share code, notes, and snippets.

@BraedonWooding
Created March 3, 2019 13:53
Show Gist options
  • Save BraedonWooding/7549f7876d425ac993a92cf5f2373359 to your computer and use it in GitHub Desktop.
Save BraedonWooding/7549f7876d425ac993a92cf5f2373359 to your computer and use it in GitHub Desktop.
#!/usr/local/bin/bash
# For when you need to count lines based on file extensions so you can accurately see the difference
# You must be on a current branch before executing this
# Pass your author name as the input i.e. `./GitLineCounter.sh MyName`
git log --numstat --oneline --author="$1" --format= > file
declare -A addedLines=()
declare -A removedLines=()
while read line; do
if ! [ -z "${line##*=>*}" ]; then
read added removed filepath <<<"$line"
filename=$(basename -- "$filepath")
extension="${filename##*.}"
if [ "$added" != "-" ]; then
if [ -z "${addedLines[$extension]}" ]; then
addedLines[$extension]=$added
else
addedLines[$extension]=${addedLines[$extension]}+$added
fi
fi
if [ "$removed" != "-" ]; then
if [ -z "${removedLines[$extension]}" ]; then
removedLines[$extension]=$removed
else
removedLines[$extension]=${removedLines[$extension]}+$removed
fi
fi
fi
done < file
for i in "${!addedLines[@]}"
do
echo "*.$i: +$(("${addedLines[$i]}")) -$(("${removedLines[$i]}"))"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment