Last active
August 14, 2019 22:03
-
-
Save rkennesson/bf928b7e6b22bf96a6e91b945487eca8 to your computer and use it in GitHub Desktop.
get size of git repo
This file contains hidden or 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
#!/usr/bin/env bash | |
#https://stackoverflow.com/a/30494746 | |
if [ "$#" -eq 2 ]; then | |
echo "$(echo "$(curl https://api.github.com/repos/$1/$2 2>/dev/null | grep size | tail -1 | tr -dc '[:digit:]')") KB" | |
elif [ "$#" -eq 1 ]; then | |
echo "$(echo "$(curl $1 2>/dev/null | grep size | tail -1 | tr -dc '[:digit:]')") KB" | |
#elif [ "$#" -eq 3 ] && [ "$1" == "-z" ]; then | |
# edit: Content-Length doesn't appear to show up anymore for a git repo. A 404 repo shows Content-Length of 15 but otherwise the | |
# field is non-existant | |
# For some reason Content-Length header is returned only on second try | |
#curl -I https://codeload.github.com/$2/$3/zip/master &>/dev/null | |
#echo "$(echo "scale=2; $(curl -I https://codeload.github.com/$2/$3/zip/master 2>/dev/null | grep Content-Length | cut -d' ' -f2 | tr -d '\r') / 1024 / 1024" | bc)MB" | |
else | |
printf "Usage: $(basename $0) [-z] OWNER REPO\n\n" | |
printf "Get github repository size or, optionally [-z], the size of the zipped\n" | |
printf "master branch (`Download ZIP` link on repo page).\n" | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment