Created
March 15, 2016 12:55
-
-
Save Boldewyn/7319f446ef74c85f5f06 to your computer and use it in GitHub Desktop.
Git command to compare size of file in working tree against index/commit
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
if [[ $1 == "--help" || $1 == "-h" ]]; then | |
cat <<USAGE | |
usage: $(basename $0) FILE [REVISION] | |
Compare file size between version at REVISION (default: index) and | |
on disk. | |
USAGE | |
exit | |
fi | |
SIZE_OLD=$(git show "$2:$1" | wc -c) | |
SIZE_NEW=$(cat "$1" | wc -c) | |
REV=${2:-index} | |
PAD_LENGTH=$(( ${#REV} > 4 ? ${#REV} : 4 )) | |
PAD_LENGTH=$(( $PAD_LENGTH + $(( $SIZE_OLD > $SIZE_NEW ? ${#SIZE_OLD} : ${#SIZE_NEW} )) )) | |
printf "Size in $REV: %$(( ${PAD_LENGTH} - ${#REV} ))d\n" "$SIZE_OLD" | |
printf "Size on file: %$(( ${PAD_LENGTH} - 4 ))d\n" "$SIZE_NEW" | |
printf "Difference: %+$(( ${PAD_LENGTH} - 4 ))d\n" "$(( $SIZE_NEW - $SIZE_OLD ))" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment