Last active
April 14, 2017 13:56
-
-
Save johnpapa/01f0e7dce60571fafacc to your computer and use it in GitHub Desktop.
git clone
This file contains hidden or 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
| # 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="johnpapa" | |
| 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