Created
October 16, 2017 10:38
-
-
Save mclarkson/5f53e0ca46e1f3989dc0b69b6818b410 to your computer and use it in GitHub Desktop.
Clone all of a user's GitHub projects
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 | |
#jsonProperty=clone_url | |
# or | |
jsonProperty=ssh_url | |
[[ -z $1 ]] && { | |
echo "Usage: $0 <GitHub User ID>" | |
exit 1 | |
} | |
which JSONPath.sh &>/dev/null | |
[[ $? -ne 0 ]] && { | |
echo "ERROR: JSONPath.sh not found in your PATH" | |
echo "Please install JSONPath.sh." | |
echo | |
exit 1 | |
} | |
GHUID=$1 | |
# Get number of pages | |
numpages=$( | |
curl -Is https://api.github.com/users/$GHUID/repos | | |
sed -n '/Link:/ { s/^.*page=\([0-9]*\)>; rel="last"/\1/p }' | |
) | |
[[ -z $numpages ]] && { | |
echo "ERROR: Could not get number of pages." | |
echo "Debug manually by typing:" | |
echo " curl -Is https://api.github.com/users/$GHUID/repos" | |
echo | |
exit 1 | |
} | |
repos=$( | |
for i in `seq 1 3`; do | |
curl -s "https://api.github.com/users/$GHUID/repos?page=$i" | | |
JSONPath.sh ".*.$jsonProperty" -b; | |
done) | |
[[ -z $repos ]] && { | |
echo "ERROR: Could not get repo list." | |
echo "Debug manually by typing:" | |
echo " curl -s \"https://api.github.com/users/$GHUID/repos?page=1\"" | |
echo | |
exit 1 | |
} | |
for repo in $repos; do | |
echo git clone $repo | |
git clone $repo | |
echo | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment