Last active
August 20, 2018 15:22
-
-
Save searls/62d5cb2f736a75c73ae2 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.
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/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/code/$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 $HOME/code/$ORG/$REPO\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
It's not 100% duplicating your Bash script, but here's one using Batch. Running through a VPN, so SSH doesn't work for me, but I left that line in there for anyone that wants to swap over to it. Also, doesn't currently handle the
org/repo
setup currently.