Skip to content

Instantly share code, notes, and snippets.

@spboyer
Forked from addyosmani/a_small_note.md
Last active September 15, 2015 19:11
Show Gist options
  • Save spboyer/d7775eb65caf08c05916 to your computer and use it in GitHub Desktop.
Save spboyer/d7775eb65caf08c05916 to your computer and use it in GitHub Desktop.
clone.sh

This let's me git clone a template repo, cd into and fire up a new template in my editor of choice:

$ clone starter # clones https://github.com/addyosmani/starter (a personal boilerplate)

$ clone h5bp html5-boilerplate # get me HTML5 Boilerplate

$ clone angular angular-seed # same for AngularJS seed

$ clone polymerlabs seed-element # same for a new Polymer element

No dependencies involved at all. Easy to add a mkdir step to this so you can do new h5bp, new boilerplate etc.

# A better git clone
# clones a repository, cds into it, and opens it in my editor.
#
# Based on https://github.com/stephenplusplus/dots/blob/master/.bash_profile#L68 by @stephenplusplus
#
# Note: code is already setup as a shortcut to VS Code. Replace with your own editor if different
#
# - arg 1 - url|username|repo remote endpoint, username on github, or name of
# repository.
# - arg 2 - (optional) name of repo
#
# usage:
# $ clone things
# .. git clone [email protected]:addyosmani/things.git things
# .. cd things
# .. code .
#
# $ clone yeoman generator
# .. git clone [email protected]:yeoman/generator.git generator
# .. cd generator
# .. code .
#
# $ clone [email protected]:addyosmani/dotfiles.git
# .. git clone [email protected]:addyosmani/dotfiles.git dotfiles
# .. cd dots
# .. code .
function clone {
# customize username to your own
local username="spboyer"
local url=$1;
local repo=$2;
if [[ ${url:0:4} == 'http' || ${url:0:3} == 'git' ]]
then
# just clone this thing.
repo=$(echo $url | awk -F/ '{print $NF}' | sed -e 's/.git$//');
elif [[ -z $repo ]]
then
# my own stuff.
repo=$url;
url="[email protected]:$username/$repo";
else
# not my own, but I know whose it is.
url="[email protected]:$url/$repo.git";
fi
git clone $url $repo && cd $repo && code .;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment