Last active
August 29, 2015 14:07
-
-
Save AkBKukU/1cc646e59e23cf872c7d to your computer and use it in GitHub Desktop.
A simple linux script to simplifiy downloading github repos
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 | |
# Usage | |
# | |
# run `gethub githubuser/repo` | |
# example `gethub github/markup` | |
pName=$1 | |
githubdir="$(echo ~)/projects" | |
githubdirpath=($(echo $githubdir | tr "/" " ")) | |
dircount=${#githubdirpath[@]} | |
midpath="/" | |
# Verify githubdir exists | |
for (( c=0; c<=$dircount; c++ )) | |
do | |
# make dir if it doesn't exist | |
if [ ! -d "$midpath${githubdirpath[$c]}" ] | |
then | |
mkdir "$midpath${githubdirpath[$c]}" | |
fi | |
midpath="$midpath${githubdirpath[$c]}/" | |
done | |
cd ~/projects | |
# 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 "/" " ")) | |
# Test if there is already a directory for the user | |
if [ ! -d "$githubdir/${path[0]}" ] | |
then | |
# Make dir if none found | |
echo "Creating user directory: $githubdir/${path[0]}" | |
mkdir "$githubdir/${path[0]}" | |
fi | |
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