Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Clone all of a user's GitHub projects
#!/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