Skip to content

Instantly share code, notes, and snippets.

@AkBKukU
Created July 17, 2018 19:15
Show Gist options
  • Save AkBKukU/da1532688c49444a5dfd491df883eb36 to your computer and use it in GitHub Desktop.
Save AkBKukU/da1532688c49444a5dfd491df883eb36 to your computer and use it in GitHub Desktop.
Download github repos into sub directories based on the creator
#!/bin/bash
# Usage
#
# run `gethub githubuser/repo`
# example `gethub github/markup`
# checkDir
# Checks to see if a directory exists and creates it and any directories needed to get to it.
function checkDir ()
{
dir="$1"
dirArray=($(echo $dir | tr "/" " "))
dircount=${#dirArray[@]}
midpath="/"
# Loop through directory array to create needed folders
for (( c=0; c<$dircount; c++ ))
do
# Make directory if it doesn't exist
if [ ! -d "$midpath${dirArray[$c]}" ]
then
cd "$midpath"
echo "Making Directory: $midpath${dirArray[$c]}"
mkdir "$fileDelim${dirArray[$c]}"
fi
midpath="$midpath${dirArray[$c]}/"
done
}
pName=$1
githubdir="$(echo ~)/git/hub"
# Make sure there is a ".git" at the end of the url
if [ "${pName:$(expr ${#pName} - 4)}" != ".git" ]
then
pName="$pName.git"
fi
path=($(echo $pName | tr "/" " "))
echo "Checking $githubdir/${path[0]}"
checkDir "$githubdir/${path[0]}"
cd "$githubdir/${path[0]}"
git clone https://github.com/$pName
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment