Last active
March 20, 2022 14:30
-
-
Save sixem/757e20d828f3259019ba5c4b23ce1b32 to your computer and use it in GitHub Desktop.
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 | |
# Clones the repos of a user and updates them if they already have been cloned. | |
mkdir -p "$1" && cd "$1" | |
TOKEN="YOUR_GITHUB_AUTH-TOKEN" | |
declare -a CLONE=() | |
declare -a PULL=() | |
FETCH=$(curl -s -H "Authorization: token $TOKEN" "https://api.github.com/users/$1/repos?per_page=100") | |
for NAME in $(echo "${FETCH}" | jq -r ".[].name"); do | |
if [ ! -d "$NAME" ]; then | |
CLONE=(${CLONE[@]} "$NAME") | |
else | |
PULL=(${PULL[@]} "$NAME") | |
fi | |
done | |
for REPO in "${PULL[@]}"; do | |
echo "$REPO exists - pulling .." | |
cd "$REPO" && git pull && cd ".." | |
done | |
for REPO in "${CLONE[@]}"; do | |
echo "Cloning $REPO .." | |
git clone "https://github.com/$1/$REPO.git" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment