Skip to content

Instantly share code, notes, and snippets.

@searls
Last active August 20, 2018 15:22
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save searls/62d5cb2f736a75c73ae2 to your computer and use it in GitHub Desktop.
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.
#!/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 "git@github.com:$ORG/$REPO.git" "$REPO_DIR"
fi
echo "cd $HOME/code/$ORG/$REPO\n" | pbcopy
echo "Hit Command-V to cd into the repo!"
@walterg2
Copy link

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.

@echo off
REM A simple script to keep a tidy %userprofile%/code directory organized by owner & then repo
REM When the script is done, just hit control-v to switch into the directory
REM (Github and Windows only. Sorry, openness!)
REM
REM Usage:
REM   gloan <org> <repo>
REM
REM example: gloan testdouble/testdouble.js
REM
REM Once cloned, will copy a "cd" command to quickly change into repo directory

set ORG=%1
set REPO=%2
set ORG_DIR=%userprofile%\code\%ORG%
set REPO_DIR=%ORG_DIR%\%REPO%

REM Make sure org directory exists
if not exist "%ORG_DIR%" mkdir "%ORG_DIR%"

REM Make sure it's not already cloned, then clone
if exist "%REPO_DIR%" echo "It looks like the repo was already cloned."

REM if not exist "%REPO_DIR%" git clone git@github.com:%ORG%/%REPO%.git %REPO_DIR%
if not exist "%REPO_DIR%" git clone https://github.com/%ORG%/%REPO%.git %REPO_DIR%

echo cd "%ORG_DIR%\%REPO%" | clip
echo "Hit Control-V to cd into the repo!"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment