Skip to content

Instantly share code, notes, and snippets.

@dzsquared
Last active December 12, 2022 01:39
Show Gist options
  • Save dzsquared/689377ad76e746498d5a04468d731959 to your computer and use it in GitHub Desktop.
Save dzsquared/689377ad76e746498d5a04468d731959 to your computer and use it in GitHub Desktop.
shell script for gpc command to git clone and open in code a repository
# 1 input argument, the git url
giturl=$1
# parse the url for the org name
org=$(echo $giturl | cut -d'/' -f4)
# check for the repo folder in ~/CodeRepos/$org
repo=$(echo $giturl | cut -d'/' -f5 | cut -d'.' -f1)
githuburl="https://api.github.com/repos/$org/$repo"
forkorg=$(curl -H "Accept: application/vnd.github+json" -H "Authorization: Bearer XXXXXXXXXXXXXXXXXXXXXXX" -H "X-GitHub-Api-Version: 2022-11-28" -s $githuburl | jq '.parent.full_name')
# remove quotes from the forkorg and split forkorg at the slash for the first part
forkorg=$(echo $forkorg | tr -d '"' | cut -d'/' -f1)
# check for the org folder in ~/CodeRepos
cd ~/CodeRepos
# check if $forkorg is null
if [ -z "$forkorg" ]; then
if [ ! -d "$org" ]; then
mkdir $org
fi
cd $org
else
if [ ! -d "$forkorg" ]; then
mkdir $forkorg
fi
cd $forkorg
fi
# echo $repo
if [ -d "$repo" ]; then
echo "Opening an existing folder..."
else
echo "Cloning the repository..."
git clone $giturl
fi
cd $repo
code .
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment