Skip to content

Instantly share code, notes, and snippets.

@kjlape
Forked from searls/gloan.sh
Last active August 20, 2018 15:23
Show Gist options
  • Save kjlape/9c879b33dedb2f70ff7c896d7bd65c22 to your computer and use it in GitHub Desktop.
Save kjlape/9c879b33dedb2f70ff7c896d7bd65c22 to your computer and use it in GitHub Desktop.
Clone into a new repo and quickly switch into it. Helps avoid a haphazard collection of unorganized github repos all over my home directory. Once it's cloned (or even if it errors), just hit Paste & it'll change into the directory of the repo.
#!/bin/sh -e
# A simple script to keep a tidy ~/code directory organized by owner & then repo
# When the script is done, just hit command-v to switch into the directory
# (Github and Mac only. Sorry, openness!)
#
# Usage:
# gloan <org>/<repo>
# Or:
# gloan <org> <repo>
#
# example: gloan testdouble/testdouble.js
#
# Once cloned, will copy a "cd" command to quickly change into repo directory
IFS='/' read -ra ADDR <<< "$1"
ORG="${ADDR[0]}"
REPO="${ADDR[1]-$2}"
ORG_DIR="$HOME/Dev/$ORG"
REPO_DIR="$ORG_DIR/$REPO"
# Make sure org directory exists
mkdir -p "$ORG_DIR"
# Make sure it's not already cloned, then clone
if [ -d "$REPO_DIR" ]; then
echo "It looks like the repo was already cloned."
else
git clone "[email protected]:$ORG/$REPO.git" "$REPO_DIR"
fi
echo "cd $REPO_DIR\n" | pbcopy
echo "Hit Command-V to cd into the repo!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment