Skip to content

Instantly share code, notes, and snippets.

@addyosmani
Last active October 16, 2021 04:40
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save addyosmani/b6c9a062266efbb0eb04 to your computer and use it in GitHub Desktop.
Save addyosmani/b6c9a062266efbb0eb04 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: subl is already setup as a shortcut to Sublime. 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 git@github.com:addyosmani/things.git things
# .. cd things
# .. subl .
#
# $ clone yeoman generator
# .. git clone git@github.com:yeoman/generator.git generator
# .. cd generator
# .. subl .
#
# $ clone git@github.com:addyosmani/dotfiles.git
# .. git clone git@github.com:addyosmani/dotfiles.git dotfiles
# .. cd dots
# .. subl .
function clone {
# customize username to your own
local username="addyosmani"
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="git@github.com:$username/$repo";
else
# not my own, but I know whose it is.
url="git@github.com:$url/$repo.git";
fi
git clone $url $repo && cd $repo && subl .;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment