Created
August 25, 2021 17:50
-
-
Save tst32/da3ee2e42417626149dcd37ebc1a029a to your computer and use it in GitHub Desktop.
allreposclone.sh is a bash script to clone all repos given github owner name
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
#!/usr/bin/env bash | |
args=("$@") | |
command -v gh >/dev/null 2>&1 || { echo >&2 "require gh (https://cli.github.com/) tool, but it's not installed. Aborting."; exit 1; } | |
set -e | |
if [ $# -eq 0 ]; then | |
echo "No arguments supplied, allreposclone.sh is a bash script to clone all repos given github owner name" | |
echo "call wuth argument <ownername> or -h|--help option to show usage" | |
echo "comment to @tst32" | |
exit 0 | |
fi | |
repowner=${args[0]} | |
if [[ $repowner == *"--help"* || $repowner == *"-h"* ]]; then | |
echo 'usage: ./allreposclone.sh <repo owner name> -- clone all (visible to you) repos' | |
echo 'as rest of you got repo_list.txt of clonned repo' | |
exit 0 | |
fi | |
if [ -e "repo_list.txt" ]; then | |
rm -f "repo_list.txt" | |
fi | |
unset x | |
shopt -s lastpipe | |
set +m | |
repstr='"' | |
for repo in $(gh repo list $repowner --json name); do | |
echo $repo | jq -S | awk '{print $2}' | sort -u -b -r | sed 's/'"^${repstr}"'/'"${repowner}"'\//g' | x=$(sed 's/"//g') | |
echo "$x" >>repo_list.txt; done | |
while read repo; do gh repo clone "$repo"; done <repo_list.txt |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment